Raja
Raja

Reputation: 249

how to Upload files using MULTIPART file upload in DROPBOX

I am trying to upload files using MULTIPART entity method.But it fails in error says that {"error": "file parameter value 'None' is invalid"}

My code is:

File file = new File("C:/Users/sst-06/Desktop/new.txt");

        service.signRequest(dropBoxToken, request); 

        HttpClient client = new DefaultHttpClient();         

        String url="https://api-content.dropbox.com/1/files/dropbox/test";

        System.out.println("URL "+url);

        HttpPost post   = new HttpPost(url);

        MultipartEntity entity = new MultipartEntity(  );
        FileBody fileBody= new FileBody( file,"application/x-unknown");
        entity.addPart( "file",fileBody);
        System.out.println(fileBody);

        for (String key : request.getHeaders().keySet()){
             post.setHeader(key, request.getHeaders().get(key));            

        }

        post.setEntity( entity );    

        String response = EntityUtils.toString( client.execute(post).getEntity(), "UTF-8" );  
        client.getConnectionManager().shutdown();
        System.out.println(response);

And my entity file contains all the parameters as mentioned.

--hkYO-pBlK0UQLXjtVKLrBkOSXz7mYe-8WBVBvAnX Content-Disposition: form-data; name="file"; filename="new.txt" Content-Type: application/x-unknown Content-Transfer-Encoding: binary

--File contents-- --hkYO-pBlK0UQLXjtVKLrBkOSXz7mYe-8WBVBvAnX--

I dont know where i felt with error.Please help.

Thanks in advance

Upvotes: 1

Views: 1118

Answers (1)

Kevin - YourCoder
Kevin - YourCoder

Reputation: 21

Is there any reason why you want to use the web service directly? Will you consider using the DropBox Java SDK?

https://www.dropbox.com/static/developers/dropbox-java-sdk-1.5.3.zip

Upvotes: 2

Related Questions