cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

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

Legalas61
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 4

Greg-DB
Dropbox Staff

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.)

Legalas61
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?

Greg-DB
Dropbox Staff

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.

Legalas61
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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Legalas61 Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?