Question

Space Upload Image By Amazon S3 Sdk But Error

Posted October 2, 2020 346 views
APIDigitalOcean Spaces

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;
        }
edited by bobbyiliev

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.

×
Submit an Answer
2 answers

Kindly did you find a solution for this problem?

Yes, I found. There is no problem anymore.

Thank you :)