简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM