Announcements
Do you have an idea for Dropbox Paper? Share it with us here!

How to insert a picture from the application on the site?

Explorer | Level 3

Hi Dropbox!
Now I am learning Django, I am creating the first application. Deployed this application to Heroku. As a file storage for pictures, I decided to use Dropbox.
Now I am adding a picture to record Django in the admin panel and it will appear in the Dropbox application, but I don’t understand how to get a link to it (so that it appears on the site).

I do this:

dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_TOKEN)
    shared_link_metadata = dbx.sharing_create_shared_link_with_settings("/" + str(post.images))

    print(shared_link_metadata)

to view.py

But I get:

ApiError('6d0d5986e4daa4aa3cb644556bd30989', CreateSharedLinkWithSettingsError('shared_link_already_exists', SharedLinkAlreadyExistsMetadata('metadata', FileLinkMetadata(url='https://www.dropbox.com/s/55dbx3w7hq6ejp2/regular_picture-e8d4091b6a6d555b697bac3f9af0d728.jpg?dl=0', name='regular_picture-e8d4091b6a6d555b697bac3f9af0d728.jpg', link_permissions=LinkPermissions(can_revoke=True, resolved_visibility=ResolvedVisibility('public', None), requested_visibility=RequestedVisibility('public', None), revoke_failure_reason=None, effective_audience=None, link_access_level=None), client_modified=datetime.datetime(2019, 11, 17, 11, 53, 39), server_modified=datetime.datetime(2019, 11, 17, 11, 53, 39), rev='01597897b57ca2a000000018cea2e10', size=79820, id='id:jC4nvt6nxLAAAAAAAAAAUg', expires=None, path_lower='/media/regular_picture-e8d4091b6a6d555b697bac3f9af0d728.jpg', team_member_info=None, content_owner_team_info=None))))


Help please ...

4 Replies

Re: How to insert a picture from the application on the site?

Dropboxer

That 'shared_link_already_exists' error indicates that the call failed because a shared link for the requested item already exists. 

You can either get the shared link information from the SharedLinkAlreadyExistsMetadata, if given in the CreateSharedLinkWithSettingsError error, as shown in your output, or call sharing_list_shared_links to retrieve it. (Likewise, you can call sharing_list_shared_links first, to check for a shared link, if you prefer.)

Reply
Loading...

Re: How to insert a picture from the application on the site?

Explorer | Level 3

Thanks for the advice! The method helped to get the link,

<img class="main_img" src="'https://www.dropbox.com/s/55dbx3w7hq6ejp2/regular_picture-e8d4091b6a6d555b697bac3f9af0d728.jpg?dl=0" alt="***">

but the browser does not display the image. Can I get a direct link, not a download link?

Reply
Loading...

Re: How to insert a picture from the application on the site?

Dropboxer

Yes, if you need direct links, you can modify the shared links returned by sharing_list_shared_links or sharing_create_shared_link_with_settings as documented in this help article.

Alternatively, if you need direct links and the links don't need to be long-lived, you can just use files_get_temporary_link instead. That returns direct links that last four hours.

Reply
Loading...

Re: How to insert a picture from the application on the site?

Explorer | Level 3

Not. Too many restrictions and difficult to implement. I solved the problem by switching to another service. Thank you for your time.

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post