0

我有一個Rails應用程序,並在控制器的行動,我可以創造一個多上傳,像這樣:所以現在的客戶端有如何檢索參考AWS :: S3 :: MultipartUpload紅寶石

def create 
    s3 = AWS::S3.new 
    bucket = s3.buckets["my_bucket"] 
    key = "some_new_file_name.ext" 
    obj = bucket.objects[key] 
    mpu = obj.multipart_upload 
    render json: { 
     :id => mpu.id 
    } 
    end 

分段上傳ID,她可以通過瀏覽器將部分上傳到aws。我希望創建另一個行動,在完成上傳後組裝這些零件。例如:

def assemble 
    s3 = AWS::S3.new 
    bucket = s3.buckets["my_bucket"] 
    key = params['key'] 
    bucket.objects[key].multipart_upload.complete 
    render json: { :status => "all good" } 
    end 

雖然這不行。如何獲取對multipartUpload對象的引用或者使用key或id創建一個新引用,以便我可以調用它的「完整」方法?任何見解表示讚賞

回答

0

我發現客戶端類的文檔中此方法並得到它的工作如下:

client = AWS::S3::Client.new 

# reassemble partsList 
partsList = [] 
params[:partsList].each do |key, pair| 
    partsList.push pair 
end 

options = { 
    :bucket_name => 'my_bucket', 
    :key => params[:key], 
    :upload_id => params[:upload_id], 
    :parts => partsList 
} 
client.complete_multipart_upload(options)