ファイルバージョンのアップロード
ファイルバージョンのアップロード
直接アップロードによってBoxにファイルの新しいバージョンをアップロードするには、ファイルのコンテンツ、目的のファイル名、フォルダIDを使用して、POST /files/:id/content APIにAPIコールを実行します。
curl -i -X POST "https://upload.box.com/api/2.0/files/12345/content" \
-H "authorization: Bearer <ACCESS_TOKEN>" \
-H "content-type: multipart/form-data" \
-F attributes='{"name":"Contract.pdf", "parent":{"id":"11446498"}}' \
-F file=@<FILE_NAME>await client.uploads.uploadFileVersion(file.id, {
attributes: {
name: file.name!,
} satisfies UploadFileVersionRequestBodyAttributesField,
file: generateByteStream(20),
} satisfies UploadFileVersionRequestBody);client.uploads.upload_file_version(
uploaded_file.id,
UploadFileVersionAttributes(name=new_file_version_name),
new_file_content_stream,
)await client.Uploads.UploadFileVersionAsync(fileId: uploadedFile.Id, requestBody: new UploadFileVersionRequestBody(attributes: new UploadFileVersionRequestBodyAttributesField(name: newFileVersionName), file: newFileContentStream));client.getUploads().uploadFileVersion(uploadedFile.getId(), new UploadFileVersionRequestBody(new UploadFileVersionRequestBodyAttributesField(newFileVersionName), newFileContentStream))await client.Uploads.UploadFileVersionAsync(fileId: uploadedFile.Id, requestBody: new UploadFileVersionRequestBody(attributes: new UploadFileVersionRequestBodyAttributesField(name: newFileVersionName), file: newFileContentStream));await client.uploads.uploadFileVersion(file.id, {
attributes: {
name: file.name!,
} satisfies UploadFileVersionRequestBodyAttributesField,
file: generateByteStream(20),
} satisfies UploadFileVersionRequestBody);リクエスト形式
このAPIのリクエスト本文には、multipart/form-dataのコンテンツタイプが使用されます。これを使用して、ファイル属性とファイルの実際のコンテンツの2つの部分を送信します。
最初の部分はattributesと呼ばれ、ファイル名や親フォルダのidなど、ファイルに関する情報を含むJSONオブジェクトが含まれています。
以下の例では、ユーザーのルートフォルダにtest.txtをアップロードしています。
POST /api/2.0/files/123/content HTTP/1.1
Host: upload.box.com
Authorization: Bearer [ACCESS_TOKEN]
content-length: 343
content-type: multipart/form-data; boundary=------------------------9fd09388d840fef1
--------------------------9fd09388d840fef1
content-disposition: form-data; name="attributes"
{"name":"test.txt", "parent":{"id":"0"}}
--------------------------9fd09388d840fef1
content-disposition: form-data; name="file"; filename="test.txt"
content-type: text/plain
Test file text.
--------------------------9fd09388d840fef1--
オプション
ファイルのアップロード時に使用できるすべてのパラメータの詳細については、このAPIコールに関するリファレンスドキュメントを参照してください。パラメータには、設定することで転送中のファイルの破損を防ぐcontent-md5や、アップロード時間とは異なる時間をファイル作成時間として明示的に指定できる機能が含まれます。
ファイルバージョンの場合、追加のif-matchヘッダーを渡すことで、アプリケーションが最後にコンテンツを検査した後で更新されたファイルが上書きされるのを防ぐことができます。
制約事項
直接アップロードできるファイルサイズの上限は50 MBです。ファイルがこれより大きい場合は、分割アップロードAPIを使用してください。
アップロードの上限は、認証済みユーザーのアカウントの種類によって決まります。詳細については、このトピックに関するBoxコミュニティの記事を参照してください。