Post to folder under a public S3 Bucket
up vote
0
down vote
favorite
I can successfully post a file object via AJAX in client javascript code from my browser to the ROOT of an s3bucket, using this code:
function upload_file(path, fileObj) {
var fd = new FormData();
fd.append('key', fileObj.name);
fd.append('acl', 'bucket-owner-full-control');
fd.append('Content-Type', fileObj.type);
fd.append("file",fileObj);
return $.ajax({
type : 'POST',
url : path,
data : fd,
processData: false, // Don't process the data
contentType: false, // Don't set contentType
success: function(json) { console.log('Upload complete!') },
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('Upload error: ' + XMLHttpRequest.responseText);
}
});
}
The destination is a test-only temporary(!) globally public S3 bucket configured as follows:




My problem is that I cannot post to any folder below the root of this bucket. Concretely put, doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/', fileObj)
results in a successful upload to root bucket.
However doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/sounds/', fileObj)
returns this error from S3:
Upload error:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>MethodNotAllowed</Code>
<Message>The specified method is not allowed against this resource.</Message>
<Method>POST</Method>
<ResourceType>OBJECT</ResourceType>
<RequestId>DC6AA872FC4F96B4</RequestId>
<HostId>/AOtAuVcXnRZrQD7Rs+EmpZ2H5YDs5TPgEjmvMpVqSdZuPbnTtE/nh4p/Fgad8v00VQ93RKer8g=</HostId>
</Error>
Since only posting to the subfolder is the problem, I assume my code is correct and that I have misconfigured my folder. What am I missing? My intent after overcoming this problem is to proceed to a more traditional pre-signed URL approach, but still wanted to get the bucket permissions sorted first.
amazon-s3 permissions acl
|
show 1 more comment
up vote
0
down vote
favorite
I can successfully post a file object via AJAX in client javascript code from my browser to the ROOT of an s3bucket, using this code:
function upload_file(path, fileObj) {
var fd = new FormData();
fd.append('key', fileObj.name);
fd.append('acl', 'bucket-owner-full-control');
fd.append('Content-Type', fileObj.type);
fd.append("file",fileObj);
return $.ajax({
type : 'POST',
url : path,
data : fd,
processData: false, // Don't process the data
contentType: false, // Don't set contentType
success: function(json) { console.log('Upload complete!') },
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('Upload error: ' + XMLHttpRequest.responseText);
}
});
}
The destination is a test-only temporary(!) globally public S3 bucket configured as follows:




My problem is that I cannot post to any folder below the root of this bucket. Concretely put, doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/', fileObj)
results in a successful upload to root bucket.
However doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/sounds/', fileObj)
returns this error from S3:
Upload error:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>MethodNotAllowed</Code>
<Message>The specified method is not allowed against this resource.</Message>
<Method>POST</Method>
<ResourceType>OBJECT</ResourceType>
<RequestId>DC6AA872FC4F96B4</RequestId>
<HostId>/AOtAuVcXnRZrQD7Rs+EmpZ2H5YDs5TPgEjmvMpVqSdZuPbnTtE/nh4p/Fgad8v00VQ93RKer8g=</HostId>
</Error>
Since only posting to the subfolder is the problem, I assume my code is correct and that I have misconfigured my folder. What am I missing? My intent after overcoming this problem is to proceed to a more traditional pre-signed URL approach, but still wanted to get the bucket permissions sorted first.
amazon-s3 permissions acl
Are the subfolder permissions the same?
– Nick Maroulis
Nov 17 at 21:31
I cannot see how to permission folders directly, Nick, and have not permissioned the folder beyond simply creating it with defaults. But I did select the folder afterwards, and via Actions made it public, just for good measure. Does one have to recreate folders after changing the bucket permissions/cors/acls?
– Mark Bordelon
Nov 17 at 21:35
Just blew away the subfolder and recreated it with the defaults (and it states that the folder inherits the same settings from bucket). Still get the same error when I try to post to it. Made it public again. Same error.
– Mark Bordelon
Nov 17 at 21:43
Your CORS configuration is correct and the error message cited in the question isn’t related to CORS. If you were having a CORS problem, you’d be getting an error message from the browser on the client side. But instead you’re getting a server-side error message. So it seems the solution the problem needs to found somewhere other than in your CORS configuration.
– sideshowbarker
Nov 17 at 22:12
I am counting on that as well. But just in case, wanted to give that config so that others wouldn't ask for it. Thanks, sideshowbarker. Do you see any issues with the other configuration?
– Mark Bordelon
Nov 17 at 22:16
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I can successfully post a file object via AJAX in client javascript code from my browser to the ROOT of an s3bucket, using this code:
function upload_file(path, fileObj) {
var fd = new FormData();
fd.append('key', fileObj.name);
fd.append('acl', 'bucket-owner-full-control');
fd.append('Content-Type', fileObj.type);
fd.append("file",fileObj);
return $.ajax({
type : 'POST',
url : path,
data : fd,
processData: false, // Don't process the data
contentType: false, // Don't set contentType
success: function(json) { console.log('Upload complete!') },
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('Upload error: ' + XMLHttpRequest.responseText);
}
});
}
The destination is a test-only temporary(!) globally public S3 bucket configured as follows:




My problem is that I cannot post to any folder below the root of this bucket. Concretely put, doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/', fileObj)
results in a successful upload to root bucket.
However doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/sounds/', fileObj)
returns this error from S3:
Upload error:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>MethodNotAllowed</Code>
<Message>The specified method is not allowed against this resource.</Message>
<Method>POST</Method>
<ResourceType>OBJECT</ResourceType>
<RequestId>DC6AA872FC4F96B4</RequestId>
<HostId>/AOtAuVcXnRZrQD7Rs+EmpZ2H5YDs5TPgEjmvMpVqSdZuPbnTtE/nh4p/Fgad8v00VQ93RKer8g=</HostId>
</Error>
Since only posting to the subfolder is the problem, I assume my code is correct and that I have misconfigured my folder. What am I missing? My intent after overcoming this problem is to proceed to a more traditional pre-signed URL approach, but still wanted to get the bucket permissions sorted first.
amazon-s3 permissions acl
I can successfully post a file object via AJAX in client javascript code from my browser to the ROOT of an s3bucket, using this code:
function upload_file(path, fileObj) {
var fd = new FormData();
fd.append('key', fileObj.name);
fd.append('acl', 'bucket-owner-full-control');
fd.append('Content-Type', fileObj.type);
fd.append("file",fileObj);
return $.ajax({
type : 'POST',
url : path,
data : fd,
processData: false, // Don't process the data
contentType: false, // Don't set contentType
success: function(json) { console.log('Upload complete!') },
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('Upload error: ' + XMLHttpRequest.responseText);
}
});
}
The destination is a test-only temporary(!) globally public S3 bucket configured as follows:




My problem is that I cannot post to any folder below the root of this bucket. Concretely put, doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/', fileObj)
results in a successful upload to root bucket.
However doing this...
upload_file('https://s3-us-west-2.amazonaws.com/bucket.example.com/sounds/', fileObj)
returns this error from S3:
Upload error:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>MethodNotAllowed</Code>
<Message>The specified method is not allowed against this resource.</Message>
<Method>POST</Method>
<ResourceType>OBJECT</ResourceType>
<RequestId>DC6AA872FC4F96B4</RequestId>
<HostId>/AOtAuVcXnRZrQD7Rs+EmpZ2H5YDs5TPgEjmvMpVqSdZuPbnTtE/nh4p/Fgad8v00VQ93RKer8g=</HostId>
</Error>
Since only posting to the subfolder is the problem, I assume my code is correct and that I have misconfigured my folder. What am I missing? My intent after overcoming this problem is to proceed to a more traditional pre-signed URL approach, but still wanted to get the bucket permissions sorted first.
amazon-s3 permissions acl
amazon-s3 permissions acl
edited Nov 17 at 22:09
sideshowbarker
29.9k136988
29.9k136988
asked Nov 17 at 21:16
Mark Bordelon
3217
3217
Are the subfolder permissions the same?
– Nick Maroulis
Nov 17 at 21:31
I cannot see how to permission folders directly, Nick, and have not permissioned the folder beyond simply creating it with defaults. But I did select the folder afterwards, and via Actions made it public, just for good measure. Does one have to recreate folders after changing the bucket permissions/cors/acls?
– Mark Bordelon
Nov 17 at 21:35
Just blew away the subfolder and recreated it with the defaults (and it states that the folder inherits the same settings from bucket). Still get the same error when I try to post to it. Made it public again. Same error.
– Mark Bordelon
Nov 17 at 21:43
Your CORS configuration is correct and the error message cited in the question isn’t related to CORS. If you were having a CORS problem, you’d be getting an error message from the browser on the client side. But instead you’re getting a server-side error message. So it seems the solution the problem needs to found somewhere other than in your CORS configuration.
– sideshowbarker
Nov 17 at 22:12
I am counting on that as well. But just in case, wanted to give that config so that others wouldn't ask for it. Thanks, sideshowbarker. Do you see any issues with the other configuration?
– Mark Bordelon
Nov 17 at 22:16
|
show 1 more comment
Are the subfolder permissions the same?
– Nick Maroulis
Nov 17 at 21:31
I cannot see how to permission folders directly, Nick, and have not permissioned the folder beyond simply creating it with defaults. But I did select the folder afterwards, and via Actions made it public, just for good measure. Does one have to recreate folders after changing the bucket permissions/cors/acls?
– Mark Bordelon
Nov 17 at 21:35
Just blew away the subfolder and recreated it with the defaults (and it states that the folder inherits the same settings from bucket). Still get the same error when I try to post to it. Made it public again. Same error.
– Mark Bordelon
Nov 17 at 21:43
Your CORS configuration is correct and the error message cited in the question isn’t related to CORS. If you were having a CORS problem, you’d be getting an error message from the browser on the client side. But instead you’re getting a server-side error message. So it seems the solution the problem needs to found somewhere other than in your CORS configuration.
– sideshowbarker
Nov 17 at 22:12
I am counting on that as well. But just in case, wanted to give that config so that others wouldn't ask for it. Thanks, sideshowbarker. Do you see any issues with the other configuration?
– Mark Bordelon
Nov 17 at 22:16
Are the subfolder permissions the same?
– Nick Maroulis
Nov 17 at 21:31
Are the subfolder permissions the same?
– Nick Maroulis
Nov 17 at 21:31
I cannot see how to permission folders directly, Nick, and have not permissioned the folder beyond simply creating it with defaults. But I did select the folder afterwards, and via Actions made it public, just for good measure. Does one have to recreate folders after changing the bucket permissions/cors/acls?
– Mark Bordelon
Nov 17 at 21:35
I cannot see how to permission folders directly, Nick, and have not permissioned the folder beyond simply creating it with defaults. But I did select the folder afterwards, and via Actions made it public, just for good measure. Does one have to recreate folders after changing the bucket permissions/cors/acls?
– Mark Bordelon
Nov 17 at 21:35
Just blew away the subfolder and recreated it with the defaults (and it states that the folder inherits the same settings from bucket). Still get the same error when I try to post to it. Made it public again. Same error.
– Mark Bordelon
Nov 17 at 21:43
Just blew away the subfolder and recreated it with the defaults (and it states that the folder inherits the same settings from bucket). Still get the same error when I try to post to it. Made it public again. Same error.
– Mark Bordelon
Nov 17 at 21:43
Your CORS configuration is correct and the error message cited in the question isn’t related to CORS. If you were having a CORS problem, you’d be getting an error message from the browser on the client side. But instead you’re getting a server-side error message. So it seems the solution the problem needs to found somewhere other than in your CORS configuration.
– sideshowbarker
Nov 17 at 22:12
Your CORS configuration is correct and the error message cited in the question isn’t related to CORS. If you were having a CORS problem, you’d be getting an error message from the browser on the client side. But instead you’re getting a server-side error message. So it seems the solution the problem needs to found somewhere other than in your CORS configuration.
– sideshowbarker
Nov 17 at 22:12
I am counting on that as well. But just in case, wanted to give that config so that others wouldn't ask for it. Thanks, sideshowbarker. Do you see any issues with the other configuration?
– Mark Bordelon
Nov 17 at 22:16
I am counting on that as well. But just in case, wanted to give that config so that others wouldn't ask for it. Thanks, sideshowbarker. Do you see any issues with the other configuration?
– Mark Bordelon
Nov 17 at 22:16
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
fd.append('key', fileObj.name);
The object key is were you specify the full path to the file, without a leading slash. The only thing that needs to be different is this line:
fd.append('key', 'sounds/' + fileObj.name);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
fd.append('key', fileObj.name);
The object key is were you specify the full path to the file, without a leading slash. The only thing that needs to be different is this line:
fd.append('key', 'sounds/' + fileObj.name);
add a comment |
up vote
2
down vote
accepted
fd.append('key', fileObj.name);
The object key is were you specify the full path to the file, without a leading slash. The only thing that needs to be different is this line:
fd.append('key', 'sounds/' + fileObj.name);
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
fd.append('key', fileObj.name);
The object key is were you specify the full path to the file, without a leading slash. The only thing that needs to be different is this line:
fd.append('key', 'sounds/' + fileObj.name);
fd.append('key', fileObj.name);
The object key is were you specify the full path to the file, without a leading slash. The only thing that needs to be different is this line:
fd.append('key', 'sounds/' + fileObj.name);
answered Nov 18 at 4:06
Michael - sqlbot
85.2k11125189
85.2k11125189
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355657%2fpost-to-folder-under-a-public-s3-bucket%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are the subfolder permissions the same?
– Nick Maroulis
Nov 17 at 21:31
I cannot see how to permission folders directly, Nick, and have not permissioned the folder beyond simply creating it with defaults. But I did select the folder afterwards, and via Actions made it public, just for good measure. Does one have to recreate folders after changing the bucket permissions/cors/acls?
– Mark Bordelon
Nov 17 at 21:35
Just blew away the subfolder and recreated it with the defaults (and it states that the folder inherits the same settings from bucket). Still get the same error when I try to post to it. Made it public again. Same error.
– Mark Bordelon
Nov 17 at 21:43
Your CORS configuration is correct and the error message cited in the question isn’t related to CORS. If you were having a CORS problem, you’d be getting an error message from the browser on the client side. But instead you’re getting a server-side error message. So it seems the solution the problem needs to found somewhere other than in your CORS configuration.
– sideshowbarker
Nov 17 at 22:12
I am counting on that as well. But just in case, wanted to give that config so that others wouldn't ask for it. Thanks, sideshowbarker. Do you see any issues with the other configuration?
– Mark Bordelon
Nov 17 at 22:16