Report this

What is the reason for this report?

Space Upload Image By Amazon S3 Sdk But Error

Posted on October 2, 2020

Hello,

I upload image from c# rest api to digital ocean space. And I use Awssdk.S3 (3.5.2.1)

I’ve been getting an upload error for a while.

ErrorCode   : InvalidArgument
ErrorMessage: Error making request with Error Code InvalidArgument and Http Status Code BadRequest. No further error information was returned by the service.

Why might be getting an error?

public bool UploadImage(StoreId storeId, string type, string subType, string fileName, string base64String)
        {
           var s3ClientConfig = new AmazonS3Config { ServiceURL = endpointUrl };
            s3Client = new AmazonS3Client(s3ClientConfig);
            byte[] bytes = Convert.FromBase64String(base64String);
            try
            {
                var fileTransferUtility = new TransferUtility(s3Client);
                var fileTransferUtilityRequest = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName + @"/" + appSettings.Environment + @"/" + storeId.ToString() + @"/" + type,
                    //FilePath = filePath,
                    StorageClass = S3StorageClass.StandardInfrequentAccess,
                    PartSize = 6291456, // 6 MB
                    Key = fileName + extension,
                    CannedACL = S3CannedACL.PublicRead,
                };

                using (var ms = new MemoryStream(bytes))
                {
                    fileTransferUtilityRequest.InputStream = ms;
                    fileTransferUtility.Upload(fileTransferUtilityRequest);
                }

                return true;
            }
            catch (AmazonS3Exception e)
            {
                logger.Error(string.Format("DigitalOcean Upload Method Error*** ErrorCode: {0} -- Message: {1}", e.ErrorCode, e.Message));
                
            }
            return false;
        }


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Kindly did you find a solution for this problem?

Yes, I found. There is no problem anymore.

Thank you :)

Excuse me, I got the same problem but I don’t know how ti solve it. Could someone help me? Thx

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.