我正在与CloudRail合作,以便将文件从dropbox上传/下载到我的安卓设备上。我不知道如何实现上传或下载方法。当我创建一个简单的files.txt上传时,文件路径目录让我迷失了方向。
我想做的是,将一个简单的字符串变量写入/读取到一个file.txt中,并将其上传到dropbox。在设备的外部内存中创建文件,然后上传它们也是一种选择。
我还在GitHub上对GitHub示例进行了一些研究,但是有很多关于可视化界面的代码,我不需要这些代码,这使我很难找到解决方案。我还找到了一些与我的需求相关的帖子,但我无法复制它。此外,我在CloudRail论坛上没有回复。
提前谢谢您的时间
private void uploadItem(final String name, final Uri uri) {
startSpinner();
new Thread(new Runnable() {
@Override
public void run() {
InputStream fs = null;
long size = -1;
try {
fs = getOwnActivity().getContentResolver().openInputStream(uri);
size = getOwnActivity().getContentResolver().openAssetFileDescriptor(uri, "r").getLength();
} catch (Exception e) {
stopSpinner();
getOwnActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Unable to access file!", Toast.LENGTH_SHORT).show();
}
});
return;
}
String next = currentPath;
if(!currentPath.equals("/")) {
next += "/";
}
next += name;
getService().upload(next, fs, size, true);
getOwnActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateList();
}
});
}
}).start();
}发布于 2018-05-18 20:51:54
使用CloudRail SDK的上传函数总共使用4个参数,如我们的文档中所描述的。
/**
* @param path The destination path for the new file
* @param stream The file content that will be uploaded
* @param size The file size measured in bytes
* @param overwrite Indicates if the file should be overwritten. Throws an error if set to false and the specified file already exists
* @throws IllegalArgumentException Null or malformatted path, null stream or negative file size
*/
void upload(
String path,
InputStream stream,
Long size,
Boolean overwrite
);如上所述,流参数应该指向应该上载的源字节(),在您的示例中,流参数当前为空。流来自何处并不重要(SD卡、磁盘、内存等)只要结果字节在流参数中发送即可。您的代码可能的解决方案是:(假设创建的文件存在并成功加载)
File temp = new File(context.getFilesDir(), String.valueOf(System.nanoTime()));
InputStream stream = new FileInputStream(temp);;
long size = temp.length();
dropbox.upload("/TestFolder",stream,size,true);https://stackoverflow.com/questions/50399579
复制相似问题