I am trying to upload a picture using AWS S3 SDK. Now this worked before but for some reason it just stopped working and I started getting this error:
Now when I click on the link it gives me a 'NoSuchKey' error:
I don't really understand this since my key is literally just a String. I'm also trying to upload something so obviously the key won't exist - I'm trying to upload it!
function initiateBucket() {
var albumBucketName = 'bucket_name';
var bucketRegion = 'us-east-1';
var IdentityPoolId = 'identity_pool_id';
AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
})
});
return new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName}
});
function upload(file, key, metaData) {
var temp = 'test';
var temp1 = "test";
if(verifyMetaData(metaData)) {
var s3 = vm.initiateBucket();
console.log(s3);
s3.upload({
Key: temp,
Body: temp1,
ACL: 'public-read',
Metadata: metaData
}, function(err, data) {
if (err) {
console.log(err.message);
return false;
}
else {
console.log("Successfully Uploaded to S3");
return true;
}
});
}
else {
console.log("Invalid MetaData");
console.log(metaData);
return false;
}
};
Whats also strange is that I followed two tutorials, put in my credentials and it worked for both. I then literally copy pasted how they configured the AWS config object into my initiateBucket function and I end up getting the same error.
This is one of the tutorials I followed (Look at "Configuring the SDK"):
.html
The other tutorial was from a blog and I don't have the link to it but my code above is the same as this tutorial from the docs. All I did was move it into a function(which is getting called) whereas in the tutorial they had it as a global variable.
Since it worked in the tutorial it can't be a configuration issue. I'm thinking it has to be something to do with that 403 error and the "NoSuchKey" error. But again, the code is the same from the tutorials and I'm just passing Strings so that doesn't make sense either.
One more thing I noticed is that the link from the 403 error is a bit odd. It begins with ""
Isn't it supposed to be s3.amazonaws//key like so?: "/...". The URLs of my files in my bucket start with s3.amazonaws and not my bucketName like the 403 error.
I don't know why these are different or if they are even supposed to be different. Nor do I know how to change the URL since I don't think I ever actually tell it what URL to go to.
Any ideas are appreciated.
Thanks.
I am trying to upload a picture using AWS S3 SDK. Now this worked before but for some reason it just stopped working and I started getting this error:
Now when I click on the link it gives me a 'NoSuchKey' error:
I don't really understand this since my key is literally just a String. I'm also trying to upload something so obviously the key won't exist - I'm trying to upload it!
function initiateBucket() {
var albumBucketName = 'bucket_name';
var bucketRegion = 'us-east-1';
var IdentityPoolId = 'identity_pool_id';
AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
})
});
return new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName}
});
function upload(file, key, metaData) {
var temp = 'test';
var temp1 = "test";
if(verifyMetaData(metaData)) {
var s3 = vm.initiateBucket();
console.log(s3);
s3.upload({
Key: temp,
Body: temp1,
ACL: 'public-read',
Metadata: metaData
}, function(err, data) {
if (err) {
console.log(err.message);
return false;
}
else {
console.log("Successfully Uploaded to S3");
return true;
}
});
}
else {
console.log("Invalid MetaData");
console.log(metaData);
return false;
}
};
Whats also strange is that I followed two tutorials, put in my credentials and it worked for both. I then literally copy pasted how they configured the AWS config object into my initiateBucket function and I end up getting the same error.
This is one of the tutorials I followed (Look at "Configuring the SDK"):
http://docs.aws.amazon./sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html
The other tutorial was from a blog and I don't have the link to it but my code above is the same as this tutorial from the docs. All I did was move it into a function(which is getting called) whereas in the tutorial they had it as a global variable.
Since it worked in the tutorial it can't be a configuration issue. I'm thinking it has to be something to do with that 403 error and the "NoSuchKey" error. But again, the code is the same from the tutorials and I'm just passing Strings so that doesn't make sense either.
One more thing I noticed is that the link from the 403 error is a bit odd. It begins with "https://mng-monet.s3.amazonaws./test"
Isn't it supposed to be s3.amazonaws//key like so?: "https://s3.amazonaws./mng-moment/test/...". The URLs of my files in my bucket start with s3.amazonaws and not my bucketName like the 403 error.
I don't know why these are different or if they are even supposed to be different. Nor do I know how to change the URL since I don't think I ever actually tell it what URL to go to.
Any ideas are appreciated.
Thanks.
Share Improve this question asked Mar 3, 2017 at 3:27 MatTaNgMatTaNg 8958 gold badges25 silver badges42 bronze badges 2-
1
Explaining the confusion (but not the reason): "Key" means two different things, here. Check your key refers to access key and secret access key, and means "Verify that you are using the correct credentials." The specified key does not exist means "the object with this object key (path/filename) does not exist in this bucket." Clicking the link tries to
GET
the object, so the error does make sense -- it's not there. The URL is valid.bucket.s3.../
is valid for all regions, including us-east-1, whiles3.../bucket/
is only valid in us-east-1 and fails for buckets in other regions. – Michael - sqlbot Commented Mar 3, 2017 at 8:55 - So if I am interpreting your ment correctly it means my key is probably okay. Since it failed to upload obviously the URL that goes to that object DNE. Does this mean its got something to do with what's inside initiateBucket()? – MatTaNg Commented Mar 3, 2017 at 14:17
1 Answer
Reset to default 5It turns out it was the meta data that was screwing everything up. Took me two days to figure out that an extra space after the meta data will throw this error. Really not a useful error message at all.