ダウンロードリンクからgoogleドライブにファイルをアップロードする方法をお探しです。Googleドライブへのリンクを含むファイルをアップロードする方法REST API v2
どのように行うのか説明しているドキュメントには何も見つかりませんでした。
EDIT:
私が見つかった二つの選択肢:
- 最初の出力である
- 第二のループからcreatedFileファイルのIDを回復するために最初の反復でありますその後、更新を行います。
最初の解決策は最も速いようです。 1つのクラウドから別のクラウドへのファイルのコピー/ペーストを実行すると、たとえばソリッドエクスプローラでははるかに高速になります。 よりよい解決策が存在する必要があります? `
@Override
protected String doInBackground(String... sUrl) {
File body = new File();
body.setTitle("some name");
String fileId = null;
File createdFile;
InputStream input = null;
ByteArrayOutputStream bos = null;
HttpURLConnection connection = null;
try {
URL url = new URL(sUrl[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
return "Server returned HTTP " + connection.getResponseCode()
+ " " + connection.getResponseMessage();
}
// download the file
input = connection.getInputStream();
bos = new ByteArrayOutputStream();
byte data[] = new byte[4096];
total = 0;
int count;
while ((count = input.read(data)) != -1) {
// allow canceling with back button
if (isCancelled()) {
input.close();
return null;
}
total += count;
bos.write(data, 0, count);
//option 2
if (fileId == null){
createdFile = mService.files().insert(body, new ByteArrayContent("", bos.toByteArray())).execute();
fileId = createdFile.getId();
}else{
createdFile = mService.files().update(fileId, createdFile, new ByteArrayContent("", bos.toByteArray())).execute();
}
}
//option 1
createdFile = mService.files().insert(body, new ByteArrayContent("", bos.toByteArray())).execute();
} catch (Exception e) {
return e.toString();
} finally {
try {
if (bos != null)
bos.close();
if (input != null)
input.close();
} catch (IOException ignored) {
}
if (connection != null)
connection.disconnect();
}
return null;
}
..............
あなたは私の解決策を教えてください。
- 最初は、ループからcreatedFileを出力します - 2番目は最初の反復で、ファイルのIDを復元してから更新します。 最初の解決策が最も速いようです。 1つのクラウドから別のクラウドへのファイルのコピー/ペーストを実行すると、たとえばソリッドエクスプローラでははるかに高速になります。 もっと良い解決策が必要ですか? – Aristide13