Camera.uploadFile
แอปจะออกคำสั่งนี้ให้กับกล้องเพื่อเริ่มอัปโหลดรูปภาพ หรือ
วิดีโอโดยตรงจากกล้องไปยังเซิร์ฟเวอร์ กล้องควรใช้
เพื่อสร้างคำขอ HTTP POST ระบุไฟล์ที่จะอัปโหลดตาม
fileUrl
และควรอัปโหลดไปยัง uploadUrl
ด้วย
การกันวงเงินที่ระบุโดย accessToken
เพิ่มคำสั่งนี้ในระดับ API แล้ว
2.1 และเกี่ยวข้องกับ
อัปโหลดโดยตรง
ซึ่งสามารถทำได้จากบรรทัดคำสั่งของคอมพิวเตอร์ดังนี้
curl -X post -H "Authorization: Bearer accessToken" -T fileUrl uploadUrl
พารามิเตอร์
fileUrl:
URL ของไฟล์ที่จะอัปโหลดไปยังเซิร์ฟเวอร์
uploadUrl:
สตริงที่แทนตำแหน่งที่จะอัปโหลดไฟล์
accessToken:
โทเค็นที่มีข้อมูลการตรวจสอบสิทธิ์สำหรับ
อัปโหลด โดยแอปจะรับและส่งไปยังกล้อง
ผลลัพธ์
ข้อผิดพลาด
missingParameter:
พารามิเตอร์บางอย่าง เช่น fileUrl
ขาดหายไป
invalidParameterName:
ชื่อพารามิเตอร์อินพุตอย่างน้อย 1 รายการ
ไม่รู้จัก
invalidParameterValue:
จดจำชื่อพารามิเตอร์อินพุตได้
แต่มีค่าที่ส่งผ่านอย่างน้อย 1 ค่าไม่ถูกต้อง ตัวอย่างเช่น ไฟล์ที่ระบุโดย
ไม่มี fileUrl
uploadError:
อัปโหลดกล้องไม่สำเร็จ
Command I/O |
|
อินพุตคำสั่ง |
{ "parameters": { "fileUrl": "URL of the file.", "uploadUrl": "A string representing where to upload the file.", "accessToken": "A token containing the authentication information." } } |
เอาต์พุตคำสั่ง |
none |
เอาต์พุตคำสั่ง (ข้อผิดพลาด) |
{ "error": { "code": "uploadError", "message": "Camera failed to upload the file." } } |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-08-21 UTC
[null,null,["อัปเดตล่าสุด 2024-08-21 UTC"],[[["This command, available in API level 2.1 and later, allows apps to instruct the camera to directly upload images or videos to a server."],["The camera uses provided parameters (`fileUrl`, `uploadUrl`, `accessToken`) to form and send an HTTP POST request to the specified server."],["Direct Upload requires obtaining an access token and providing the file's URL and the server's upload URL within the command parameters."],["While the command itself returns no result, potential errors during the upload process can be indicated by specific error codes like `uploadError` or `invalidParameterValue`."]]],["The app directs the camera to upload a file to a server using an HTTP POST request. Key parameters include `fileUrl` (the file's location), `uploadUrl` (the destination), and `accessToken` (authorization token). The camera utilizes these parameters to perform the upload. No direct result is returned upon command execution, but error messages such as `missingParameter`, `invalidParameterValue` or `uploadError` will be returned if the command is not correctly executed. This feature was introduced in API level 2.1.\n"]]