Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

API error while trying to upload File

Answered
New post

Comments

7 comments

  • jcleblanc

    Hi akubatoor,

     

    Would you happen to have the error message that's sent with the 400 status code in the Box API response? That'll help narrow down the reason for the 400.

     

    Thanks,

    Jon

    0
    Comment actions Permalink
  • akubatoor

    The response is 400 item_name_invalid

     

    0
    Comment actions Permalink
  • tonyjin

    From https://community.box.com/t5/Managing-Content-Troubleshooting/File-and-Folder-Upload-Issues/ta-p/306

     

    Verify that the file's name is valid. Box only supports file or folder names that are 255 characters or less. File names containing non-printable ascii, "/" or "\", names with leading or trailing spaces, and the special names “.” and “..” are also unsupported.

     

    0
    Comment actions Permalink
  • akubatoor

    I don't think I'm giving any invalid file name. I'm trying to upload a file with the name taxdoc.txt. Below the API response I'm seeing

     

    {"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value '{\"name\":\"taxdoc.txt\", \"parent\":{\"id\":\"0\"}'. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"***number removed for privacy***597673fe85807"}
    0
    Comment actions Permalink
  • kendomen

    I just ran your code and made one change and it seems to work fine.

    I changed pathfileName to fileName in the method call folder.uploadFile()

     

    if (!fileExists) {
        System.out.println("uploading new file: " + fileName);
        FileInputStream stream = new FileInputStream(pathFileName);
        BoxFile.Info boxInfo = folder.uploadFile(stream, fileName);  // <- this is just the name and not the full path
        fileId = boxInfo.getID();
        stream.close();
    }

     

     

    0
    Comment actions Permalink
  • akubatoor

    Yeah right..I also had changed the code a little bit to get this working. I changed it something like below

     

    if (!fileExists) {
                    FileInputStream stream = new FileInputStream(pathFileName);
                    FileUploadParams fileUploadParams = new FileUploadParams();
                    fileUploadParams.setName();
                    fileUploadParams.setContent(stream);
                    BoxFile.Info boxInfo = folder.uploadFile(fileUploadParams);
                    fileId = boxInfo.getID();
                    stream.close();
                }

     

    0
    Comment actions Permalink
  • lingamp

    Hey,

     

    what is the value FILE inside concat method/ where do you initialize it ?

     

     

    Thanks,

    limanp

    0
    Comment actions Permalink

Please sign in to leave a comment.