★ wanayoo — archive 1999 https://github.com/datadesk/python-documentcloud/issues/80Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does the 'project' kwarg work on upload and upload directory? I'm cornfused #80

Open
palewire opened this issue Dec 21, 2012 · 13 comments
Open
Labels

Comments

@palewire
Copy link
Member

@palewire palewire commented Dec 21, 2012

No description provided.

@jywsn
Copy link

@jywsn jywsn commented Oct 22, 2015

It definitely works on DocumentClient.upload. I haven't used upload_directory, but that method uses upload, so it should work.

@siccovansas
Copy link

@siccovansas siccovansas commented Nov 23, 2015

There is some inconsistency with client.documents.upload and the project argument. When uploading a PDF file from your computer you can only use a string in the project argument, but when you link to a PDF URL it accepts both a string and an integer. It took me some time to understand why uploading did not work anymore when I switched from using URLs to local files, so fixing this might avoid some frustration for others :D

@palewire
Copy link
Member Author

@palewire palewire commented Nov 23, 2015

Sorry for this confusion. I'll take a look at it. Though could you please clarify what you mean when you say "link to a PDF url."

@siccovansas
Copy link

@siccovansas siccovansas commented Nov 23, 2015

Thanks!
To clarify, see https://python-documentcloud.readthedocs.org/en/latest/documents.html#uploading
It says: You can also URLs link to PDFs, if that’s the kind of thing you want to do.
client.documents.upload("http://ord.legistar.com/Chicago/attachments/e3a0cbcb-044d-4ec3-9848-23c5692b1943.pdf")

@palewire
Copy link
Member Author

@palewire palewire commented Nov 24, 2015

Weird. Now that's something I hadn't considered.

Regardless of how you submit a document, the project keyword argument is passed along in the same format by this bit of code.

The one differnece I see that is URL uploads do not use a "multipart" post handler to pass along all that PDF data. Though I'm not sure that should make much difference.

Can you provide some examples of the code you're running that's not working? Are there error messages?

@cjwinchester
Copy link

@cjwinchester cjwinchester commented Mar 7, 2016

I've been running into an ish when I try to upload to a specific project. Here's the function I'm calling:

from documentcloud import DocumentCloud
import os


def dc_upload_handler(fileobj, title, description, proj_name, access_level):
    dc_username = os.environ['DC_USERNAME']
    dc_password = os.environ['DC_PASSWORD']
    client = DocumentCloud(dc_username, dc_password)
    obj = client.documents.upload(
        fileobj,
        title=title,
        description=description,
        project=proj_name,
        access=access_level
    )
    return client.documents.get(obj.id)

I'm not getting any errors, and the document uploads fine -- it's just not attached to the project I specified. I've confirmed that the string I'm passing for the project matches the name of the project on DC. I also tried fetching the project first -- client.projects.get_by_title(proj_name) -- and then passing that as the parameter to the upload function, but no dice.

@palewire
Copy link
Member Author

@palewire palewire commented Mar 7, 2016

What are you passing in as the proj_name variable?

@cjwinchester
Copy link

@cjwinchester cjwinchester commented Mar 7, 2016

The project name as a string. E.g.: dc_upload_handler("test.pf", "Title", "Description of PDF", "Project Name", "public")

@palewire
Copy link
Member Author

@palewire palewire commented Mar 7, 2016

According to the official API documentation, DocumentCloud expected the "numeric Project id" for that input. Try that and see if that works.

@cjwinchester
Copy link

@cjwinchester cjwinchester commented Mar 7, 2016

Bingo. Thanks.

@palewire
Copy link
Member Author

@palewire palewire commented Mar 7, 2016

This is something we should spell out more clearly in the documentation. I'm curious where you looked that failed to make this need clear.

@cjwinchester
Copy link

@cjwinchester cjwinchester commented Mar 7, 2016

Documents >> uploading. My though process was: if you can fetch a project by either its ID or title, maybe you could also post to one in the same way. (I might add a few lines to my function to fetch the project by name and return the ID.)

@palewire
Copy link
Member Author

@palewire palewire commented Mar 7, 2016

yeah that's a pretty reasonable thing to think. I wonder if we should be testing if an object is submitted, and if so pulling the ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.