Module: JPSClient::API::File
- Included in:
- Client
- Defined in:
- lib/jpsclient/api/file.rb
Overview
文件上传相关 API 处理 /api/file/* 路径的所有接口
Instance Method Summary collapse
-
#complete_file_multipart(s3_key:, upload_id:, upload_config:) ⇒ Object
完成多部分上传.
-
#get_file_sign_url(s3_key:, upload_id:, part_id:, content_type: "", upload_config:) ⇒ Object
获取分片预签名URL.
-
#get_simple_sign_url(s3_key:, content_type: "", upload_config:) ⇒ Hash
获取简单上传预签名URL(用于小文件直接上传,使用 media 配置).
-
#init_file_multipart(s3_key:, content_type: "", upload_config:) ⇒ Object
初始化多部分上传.
Instance Method Details
#complete_file_multipart(s3_key:, upload_id:, upload_config:) ⇒ Object
完成多部分上传
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jpsclient/api/file.rb', line 74 def complete_file_multipart(s3_key:, upload_id:, upload_config:) config = @request_config && @request_config["file_complete_multipart"] raise JPSClient::ExceptionError, "Missing config for file_complete_multipart" unless config && config["url"] path = config["url"] body_params = { s3Key: s3_key, uploadId: upload_id, uploadType: upload_config.upload_type, bucketName: upload_config.bucket_name, region: upload_config.region } return request_with_auth(:post, path, body: body_params) end |
#get_file_sign_url(s3_key:, upload_id:, part_id:, content_type: "", upload_config:) ⇒ Object
获取分片预签名URL
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/jpsclient/api/file.rb', line 54 def get_file_sign_url(s3_key:, upload_id:, part_id:, content_type: "", upload_config:) config = @request_config && @request_config["file_sign_url"] raise JPSClient::ExceptionError, "Missing config for file_sign_url" unless config && config["url"] path = config["url"] body_params = { s3Key: s3_key, contentType: content_type, uploadType: upload_config.upload_type, uploadId: upload_id, partId: part_id, bucketName: upload_config.bucket_name, region: upload_config.region } return request_with_auth(:post, path, body: body_params) end |
#get_simple_sign_url(s3_key:, content_type: "", upload_config:) ⇒ Hash
获取简单上传预签名URL(用于小文件直接上传,使用 media 配置)
传了 contentType 时服务端会把 content-type 纳入签名(X-Amz-SignedHeaders 含 content-type),调用方 PUT 时必须发送完全相同的值,否则 S3 返回 403
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jpsclient/api/file.rb', line 34 def get_simple_sign_url(s3_key:, content_type: "", upload_config:) config = @request_config && @request_config["file_sign_url"] raise JPSClient::ExceptionError, "Missing config for file_sign_url" unless config && config["url"] path = config["url"] body_params = { s3Key: s3_key, contentType: content_type, uploadType: upload_config.upload_type, bucketName: upload_config.media_bucket_name, region: upload_config.media_region } return request_with_auth(:post, path, body: body_params) end |
#init_file_multipart(s3_key:, content_type: "", upload_config:) ⇒ Object
初始化多部分上传
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jpsclient/api/file.rb', line 8 def init_file_multipart(s3_key:, content_type: "", upload_config:) config = @request_config && @request_config["file_init_multipart"] raise JPSClient::ExceptionError, "Missing config for file_init_multipart" unless config && config["url"] path = config["url"] body_params = { s3Key: s3_key, contentType: content_type, uploadType: upload_config.upload_type, bucketName: upload_config.bucket_name, region: upload_config.region } return request_with_auth(:post, path, body: body_params) end |