You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

gdiazderada's avatar
gdiazderada
Explorer | Level 4
7 years ago

Chooser - Set dropbox file as input type file value

Hi there,

 

I'm using the chooser to allow the user to select a file which then should be set as the value of an input type=file of a form. Right now I'm trying to do this within the chooser success callback but doesn't work:

 

function DropboxChooser(selector)
{
    options = {

        // Required. Called when a user selects an item in the Chooser.
        success: function (files) {
// Also tried with the files property of the input document.querySelector(selector).value = files[0]; }, // Optional. Called when the user closes the dialog without selecting a file // and does not include any parameters. cancel: function () { }, // Optional. "preview" (default) is a preview link to the document for sharing, // "direct" is an expiring link to download the contents of the file. For more // information about link types, see Link types below. linkType: "direct", // or "direct" // Optional. A value of false (default) limits selection to a single file, while // true enables multiple file selection. multiselect: false, // or true // Optional. This is a list of file extensions. If specified, the user will // only be able to select files with these extensions. You may also specify // file types, such as "video" or "images" in the list. For more information, // see File types below. By default, all extensions are allowed. extensions: ['.pdf', '.doc', '.docx'], }; Dropbox.choose(options); }

What I'm missing here?

Thanks

  • Greg-DB's avatar
    Greg-DB
    7 years ago

    Thanks for following up with the additional information. It sounds like the Dropbox portion of this is working properly then, so I'm afraid I can't be of much help.

    From your description, you're having trouble with the rest of the HTML/JavaScript work to be done with your app. That's outside the scope of Dropbox API support unfortunately.

    For reference though, the Dropbox Chooser returns link(s) for the selected file(s) back to your app, not File objects or file data. (That way, all of the file data doesn't need to be sent through the user's browser.) What you do with those is up to you, but you generally would just send the link(s) up to your server, i.e., as text, not files.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    Can you elaborate on what exactly isn't working for you? For example, is the success callback getting called? What error do you get?

    It looks like you're to set the value of some element to files[0], but each element in that array is a JSON object as documented here:

    https://www.dropbox.com/developers/chooser#response
    • gdiazderada's avatar
      gdiazderada
      Explorer | Level 4

      The callback is being fired properly, the problem is it seems I cannot set the files property of an input of type file since it's readonly.

      I got a form with an input file so the user can upload files from the computer. Also wanted to give the user the ability to upload files from the Dropbox picker, but I'm not sure how to handle that in terms of form submission and handling.

       

      Thanks

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Thanks for following up with the additional information. It sounds like the Dropbox portion of this is working properly then, so I'm afraid I can't be of much help.

        From your description, you're having trouble with the rest of the HTML/JavaScript work to be done with your app. That's outside the scope of Dropbox API support unfortunately.

        For reference though, the Dropbox Chooser returns link(s) for the selected file(s) back to your app, not File objects or file data. (That way, all of the file data doesn't need to be sent through the user's browser.) What you do with those is up to you, but you generally would just send the link(s) up to your server, i.e., as text, not files.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 3 days ago
333 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!