Circa una volta \ settimana un caricamento di file non riesce quando si salva su Amazon S3 (1 \ 300). Il codice seguente funziona abbastanza bene per confermare che il file è stato salvato correttamente, ma non posso fare a meno di pensare che ci sia un modo migliore. Quando un file non funziona, non viene generata alcuna eccezione, quindi non sono mai veramente sicuro di dove si trova il problema. Qualche suggerimento per una migliore conferma?Amazon S3 PutObject() restituisce il valore per confermare il successo?
AmazonS3Config _s3Config = new AmazonS3Config
{
ServiceURL = "s3.amazonaws.com",
CommunicationProtocol = Protocol.HTTPS,
};
using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client("accessKey", "secretAccessKey", _s3Config))
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("bucketName")
.WithFilePath("filePath")
.WithKey("keyName");
request.WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256);
PutObjectResponse response = client.PutObject(request);
// what property from the response object can I check to confirm success???
}
// the following DoesObjectExist() function uses the GetObjectMetadata() function
if (!DoesObjectExist(keyName))
throw new Exception("Failed!");
Nella regione di default standard USA, S3 fornisce scrive alla fine coerenti. Effettuare una chiamata 'GetObjectMetadata()' immediatamente dopo un 'PutObject()' può dare un 404, perché l'oggetto non è stato ancora copiato su tutti i data center. Il tuo codice sopra potrebbe generare un'eccezione, anche quando il put è andato a buon fine. Il client AmazonS3 genererà un'eccezione se si è verificato un errore, sul lato client o sul lato server. –