android dropbox目录,通过Android上传文件到Dropbox文件夹

我想让用户发送一些应用程序相关的文件给我。我在我的下拉框中为此做了一个“文件请求”文件夹。每当我收到这条消息Error 405 - Method not allowed。这里是我的代码:通过Android上传文件到Dropbox文件夹

private class UploadFile extends AsyncTask {

@Override

protected Void doInBackground(Void... params) {

try {

String sourceFileUri = "/data/com.mostafa.android.roadbump/databases/matab.db";

HttpURLConnection conn = null;

DataOutputStream dos = null;

String lineEnd = "\r\n";

String twoHyphens = "--";

String boundary = "*****";

int bytesRead, bytesAvailable, bufferSize;

byte[] buffer;

int maxBufferSize = 1 * 1024 * 1024;

if (dB.isFile()) {

try {

String upLoadServerUri = "https://www.dropbox.com/request/KJcdVMDyxHvM2So1mJkK";

// open a URL connection to the Server

FileInputStream fileInputStream = new FileInputStream(dB);

URL url = new URL(upLoadServerUri);

// Open a HTTP connection to the URL

conn = (HttpURLConnection) url.openConnection();

conn.setDoInput(true); // Allow Inputs

conn.setDoOutput(true); // Allow Outputs

conn.setUseCaches(false); // Don't use a Cached Copy

conn.setRequestMethod("PUT");

conn.setRequestProperty("Connection", "Keep-Alive");

conn.setRequestProperty("ENCTYPE", "multipart/form-data");

conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);

conn.setRequestProperty("bill", sourceFileUri);

dos = new DataOutputStream(conn.getOutputStream());

dos.writeBytes(twoHyphens + boundary + lineEnd);

dos.writeBytes("Content-Disposition: form-data; name=\"bill\";filename=\""

+ sourceFileUri + "\"" + lineEnd);

dos.writeBytes(lineEnd);

// create a buffer of maximum size

bytesAvailable = fileInputStream.available();

bufferSize = Math.min(bytesAvailable, maxBufferSize);

buffer = new byte[bufferSize];

// read file and write it into form...

bytesRead = fileInputStream.read(buffer, 0, bufferSize);

while (bytesRead > 0) {

dos.write(buffer, 0, bufferSize);

bytesAvailable = fileInputStream.available();

bufferSize = Math

.min(bytesAvailable, maxBufferSize);

bytesRead = fileInputStream.read(buffer, 0,

bufferSize);

}

// send multipart form data necesssary after file

// data...

dos.writeBytes(lineEnd);

dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

Log.d("Sasaaa", "Done");

int responseCode = conn.getResponseCode();

String responseMessage = conn.getResponseMessage();

Log.d("Sasaaa", String.valueOf(responseCode));

Log.d("Sasaaa", responseMessage);

// close the streams //

conn.disconnect();

fileInputStream.close();

dos.flush();

dos.close();

} catch (Exception e) {

e.printStackTrace();

}

}

} catch (Exception ex) {

ex.printStackTrace();

}

return null;

}

}

+0

Dropbox不提供用于上传文件请求的编程接口。我们会将其视为功能请求。程序上传应通过API完成,如下面的答案中所述。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值