parse-community / parse-server-s3-adapter

AWS S3 file storage adapter for Parse Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoSuchKey error for some files uploaded to s3

funkenstrahlen opened this issue · comments

I use this adapter for a very long time now. Never had any issues. Now I get this error from time to time:

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>
4f4e252ea6757eec0c90307b6e152f56_a6095bf7cea57864bf955f59741461a4_11dc6c3d96f7945768b2fb59449cd544.jpeg_thumbnail.jpg
</Key>
<RequestId>EBEC91AC41BCCD15</RequestId>
<HostId>
K+QlkcrNDlLaY3eNkON9/9AwTDQpUJCKhQ7YHfe0sAROFuV87Gq9Luvpq+lYdVZ5gS5LnLK8LvM=
</HostId>
</Error>

I see the link to the file in Parse Dashboard just fine. Looks like any other file link. But some of them simply return this error.

It is very difficult for me to reproduce this. I use the files for coverart images currently. When I delete the files via parse dashboard and rerun the thumbnail generator it generates the coverarts files just fine and I can access them as usual.

This is how I generate the thumbnails:

function generateThumbnail(channel, size, coverartThumbnailAttributeName){
	if (!channel.has(coverartThumbnailAttributeName)) {
		var coverartUrl = channel.get("coverart").url();
		if(coverartUrl === ""){
			logger.debug("coverart url empty. can not generate a thumbnail.");
			return Parse.Promise.as();
		}
		logger.debug("generating thumbnail for " + channel.get("name") + ". Size: " + coverartThumbnailAttributeName);

		return Parse.Cloud.httpRequest({
			url: coverartUrl,
			followRedirects: true
		}).then(function(response) {
			var image = new Image();
			return image.setData(response.buffer);
		}).then(function(image) {
			return image.resize({ width: size, height: size, ignoreAspectRatio: true });
		}).then(function(image) {
			return image.setFormat('JPEG');
		}).then(function(image) {
			return image.data();
		}).then(function(buffer) {
			logger.debug("Buffer returned, creating Parse File");
			var base64Buffer = buffer.toString("base64");
			var filename = channel.get("coverart").name() + "_thumbnail.jpg";
			var file = new Parse.File(filename, { base64: base64Buffer }, "image/jpeg");
			return file.save();
		}).then(function(file) {
			logger.debug("Thumbnail saved");
			channel.set(coverartThumbnailAttributeName, file);
		});
	}
	return Parse.Promise.as(); // this is already resolved promise
}

So only if file.save() succeeds a reference to the file is set to the channel object. Therefore I suspect the error in file.save() because it returns successfully but the created AWS file is not valid.

This started happening after changing my parse server version from 2.4.2 to 2.7.4.

Any ideas what could cause this issue?

Any other infos? Pretty tough to debug as it stands

Yes unfortunately this is very hard to debug. I do not have any news on this.

I saw this happening two times now. All the other times it worked fine as expected. However this is not heavily used on my server because new thumbnails only have to be generated 3-5 times a week for some objects.

I do not know what causes the problem. I do not see any error in my logs.

That’s very odd indeed. Keep us posted. This is perhaps a bad upload on S3 that isn’t caught correctly by the adapter

I still see this error from time to time. Weird that it does not cause any error message and does only fail sometimes. Am I the only one with this bug?

I am going to close this. please re-open if it is an issue.