Bucket

分批上傳物件

Bucket 簡單說明及自身經驗

參考資料:官方文件 GitHub:sdk-example GitHub:source code

原本已經有寫過上傳物件,為什麼又要再多寫一篇 V2 版本 因為Amazon S3 Java SDK 有出 V2,沒錯你沒看錯,這句就是廢話。 主要原因是在使用V1時,當遇到大檔案上傳時,要採用分批上傳,發現會出現錯誤。

// Error message
com.amazonaws.request - Received error response: 
com.amazonaws.services.s3.model.AmazonS3Exception: 
Your socket connection to the server was not read from or written to within the timeout period.Idle connections will be closed. 
(
    Service: Amazon S3; 
    Status Code: 400; 
    Error Code: RequestTimeout; 
    Request ID: RequestIdxxxxxx; 
    S3 Extended Request ID: base64IDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=; 
    Proxy: null), 
S3 Extended Request ID: base64IDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
// Amazon config init > set-up the client
AmazonS3 s3client = AmazonS3ClientBuilder
		.standard()
		.withCredentials(new AWSStaticCredentialsProvider(credentials))
		.withClientConfiguration(new ClientConfiguration().withConnectionTimeout(15 * 60 * 1000))
		.withRegion(Regions.fromName(area))
		.build();

不管怎麼去設定timeout時間,都沒辦法解決這個問題,只好採取其他辦法,不然專案會趕不出來....😂 廢話就不再說了上code,使用Gradle建構工具,他souce code 有說到不建議無腦引用SDK,還是依據使用需求引用相對應得package

client config

client config有很多種認證的方式,我是使用accessKey的這個方式去認證。

service

source code大致上就這樣,其他上傳物件等方式大同小異就不特別補上了🚬💨

Last updated