Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

Access-Control-Allow-Origin responses in Standard OAuth2.0 App

Answered
New post

Comments

1 comment

  • MangoCats

    Working now... needed to wrap the file data in a Blob (the filename passed to the Blob creator is ignored):

     

    $scope.sendFile = function sendFile()
    { const foo = new FormData();
    foo.append( 'attributes', '{"name":"testFileName","parent":{"id":"0"}}' );
    foo.append( 'file', new Blob( ["mary had\na little lamb"],{type:"text/plain"}) );
    var req =
    { method: 'POST',
    url: 'https://upload.box.com/api/2.0/files/content',
    headers: { 'Authorization': 'Bearer $$boxAccessToken$$',
    'Content-Type': undefined
    },
    data: foo
    };
    $http( req ).then( sendFile2, netFailHandler );
    }

     

    The working request body looks like this, seems like having the Content-Type specified on the file part of the body is what was missing:

     

    -----------------------------420sep
    Content-Disposition: form-data; name="attributes"

    {"name":"testFileName","parent":{"id":"0"}}
    -----------------------------420sep
    Content-Disposition: form-data; name="file"; filename="blob"
    Content-Type: text/plain

    mary had
    a little lamb
    -----------------------------420sep--

     

    0
    Comment actions Permalink

Please sign in to leave a comment.