I am trying to use s3-transfer-manager(2.17.167-PREVIEW) to upload file to s3 bucket. Getting below exception.
S3TransferManager s3TransferManager = S3TransferManager.builder().s3ClientConfiguration(cfg -> cfg
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create("*********", "**********************************")))
.region(Region.AP_NORTHEAST_1)).build();
Upload upload = s3TransferManager.upload(u -> u.putObjectRequest(req -> req.bucket(bucketName).key(objectKey))
.requestBody(AsyncRequestBody.fromBytes(dataAsBytes)));
return Mono.just(upload.completionFuture().join().response()).doOnError(throwable -> {
log.error(throwable.getMessage());
throw new SystemException("Exception occurred while Uploading file to S3 bucket");
});
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Failed to send the request. CRT error code: 1069
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:102) ~[sdk-core-2.17.167.jar:?]
at software.amazon.awssdk.core.exception.SdkClientException.create(SdkClientException.java:43) ~[sdk-core-2.17.167.jar:?]
at software.amazon.awssdk.transfer.s3.internal.S3CrtResponseHandlerAdapter.handleError(S3CrtResponseHandlerAdapter.java:86)
Using S3AsyncClient I am able to upload to same bucket with same credentials but transfermanager gives error. Bucket name does not have any special character.
Related
Im using action text with trix for my rich text content and Im able to upload images on my trix editor which is then uploaded to my amazon s3 bucket successfully.
I'd liek to be able to delete that object in s3 when a user decides to delete the image on the editor.
I'm using the AWS sdk for js and I've set my parameters:
window.addEventListener("trix-attachment-remove", function(event) {
var AWS = require('aws-sdk');
AWS.config.credentials = {
accessKeyId: gon.accessKey,
secretAccessKey: gon.secretKey,
region: 'us-west-1'
}
console.log(event.attachment.getAttributes())
var s3 = new AWS.S3();
var params = { Bucket: gon.bucketName, Key: '#object-name#' };
s3.deleteObject(params, function(err, data) {
if (err) console.log(err, err.stack); // error
else console.log(); // deleted
});
})
So my only issue now is getting the key for the object which I understand is the object name. So here's a sample of my objects in s3 bucket with their names:
And Im trying to get the attributes from the file which Im removing. From this code
event.attachment.getAttributes()
And heres what Im getting:
There's no way the sgid or the string at the end of the url matches any of the object name. Its simply too long. How do I get the object name in s3 when Im removign the object?
Also, just an additional note, if I replace the key with the object name directly from s3 bucket, the delete succeeds so I know its working but I just need to get hte correct object name.
I am trying to have images uploaded via my trix editor and also want to upload the images to AWS S3.
The images are getting succesfully uploaded to ActiveStorage but they are not getting uploaded to S3.
I however see something like this in the rails console Generated URL for file at key: Gsgdc7Jp84wYTQ1W4s (https://bucket.s3.amazonaws.com/Gsgdc7Jp84wYT2Ya3gxQ1W4s?X-Amz-Algorithm=AWS4redential=AKIAX6%2F20200414%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241821Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-md5%3Bcontent-type%3Bhost&X-Amz-Signature=3613d41915e47baaa7c90421eee3f0ffc)
I see that trix documentation provides attachments.js, which uploads to cloud provider https://trix-editor.org/js/attachments.js.
Also below is my relevant part of my code which is used to upload to ActiveStorage
document.addEventListener('trix-attachment-add', function (event) {
var file = event.attachment.file;
if (file) {
var upload = new window.ActiveStorage.DirectUpload(file,'/rails/active_storage/direct_uploads', window);
upload.create((error, attributes) => {
if (error) {
return false;
} else {
return event.attachment.setAttributes({
url: `/rails/active_storage/blobs/${attributes.signed_id}/${attributes.filename}`,
href: `/rails/active_storage/blobs/${attributes.signed_id}/${attributes.filename}`,
});
}
});
}
});
Below are my questions:
1) If my active storage is configured to upload to S3, do i still need attachments.js
2) My active storage is configured to upload to S3 and i see the above response in rails console but do not see the file in S3.
Any help in fixing this would be really great. Thanks.
I am trying to upload the file to s3 server, using s3_direct_upload gem. I have followed the instruction in document. But I am unable to upload the file. I am getting following error:
<Code>InvalidRequest</Code>
<Message>The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.</Message>
My bucket region is us-east-2.
And following is my initializer content:
S3DirectUpload.config do |c|
c.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
c.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
c.bucket = ENV["AWS_S3_BUCKET"]
c.region = ENV["AWS_REGION"]
c.url = "https://#{ENV['AWS_S3_BUCKET']}.s3.amazonaws.com"
end
I'm trying to upload a file to amazon s3 but I'm getting the following error:
Aws::S3::Errors::PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
Here is how I'm doing it:
s3 = Aws::S3::Resource.new(
credentials: Aws::Credentials.new('xxxx', 'xxx'),
region: 'us-west-2'
)
obj = s3.bucket('dev.media.xxx.com.br').object('key')
obj.upload_file('/Users/andrefurquin/Desktop/teste.pdf', acl:'public-read')
obj.public_url
I'm sure I'm using the right region, credentials etc..
What can I do ?
How can I upload a ActionDispatch::Http::UploadedFile to Amazon S3?
#file_data = params[:upload][:file]
s3 = AWS::S3.new
obj = s3.buckets['WeMake'].objects.create("video", file)
I then get this error: ArgumentError (:data must be provided as a String, Pathname, File, or an object that responds to #read and #eof?):
I needed to access the actual file, params[:upload][:file].tempfile and add a file extension to the s3 upload, obj = s3.buckets['Bucket'].objects.create("video.mov", #file_data.tempfile).