简体   繁体   中英

AWS S3 transferutility UploadAsync succeeds but does not create file

I got to upload file & streams to S3 periodically and the file size usually under 50MB. What am seeing is TransferUtility.UploadAsync method returns success but the file was never created. This occurs sporadically. Below is the code we use. Any suggestions around this?

public TransferUtilityUploadRequest CreateRequest(string bucket, string path)
    {
        var request = new TransferUtilityUploadRequest
        {
            BucketName = bucket,
            StorageClass = S3StorageClass.Standard,
            Key = path,
            AutoCloseStream = true,
            CannedACL = S3CannedACL.AuthenticatedRead,
            ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256
        };


        return request;
    }

    public async Task CreateS3ObjectFromStreamAsync(MemoryStream memeoryStream, string bucket, string filePath)
    {                
                var ftu = new TransferUtility(client);
                var request = CreateRequest(bucket, filePath);
                request.InputStream = memeoryStream;
                await ftu.UploadAsync(request);           

    }

    public async Task CreateS3ObjectFromFileAsync(string sourceFilePath, string bucketName, string destpath)
    {
                var request = CreateRequest(bucketName, destpath);
                request.FilePath = sourceFilePath;
                var ftu = new TransferUtility(client);
                await ftu.UploadAsync(request);                       
    }

Please use Upload or UploadAsync.Wait. It worked for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM