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
Submit an answer

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