amplify-js: Storage.get('file') should throw an error if file does not exist
Do you want to request a feature or report a bug? Feature
What is the current behavior?
Storage.get(‘file’) resolves to a presigned URL, whether or not the file exists.
This is a problem because the URL results in a 404, which means an extra step is needed to check the validity of the URL.
It’s especially a problem in Angular, when using constructs such as the following in the ionic aws starter project.
account.ts, lines 42-45
refreshAvatar() {
Storage.get(this.userId + '/avatar')
.then(url => this.avatarPhoto = (url as string));
}
account.html, line 12
<div *ngIf="avatarPhoto" class="avatar" [style.background-image]="'url('+ avatarPhoto +')'">
What is the expected behavior?
Storage.get(‘file’) should return an error that can be handled using catch or if (error).
The current documentation doesn’t specify what is returned on failure, so this change won’t be a problem there.
However, this would be a breaking change for code that relies on the current behaviour. One option is to simply accept the breaking change. Another option is to add a third parameter to the method, for the sake of discussion, called “safe,” to request this new behaviour.
Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?
0.4.6
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 23
- Comments: 26 (6 by maintainers)
I’m currently working with someone who experiencing this issue as well. The problem is that they can’t call download because the files are very large and that would be a terrible user experience, and doing
Storage.list()seems like a bad workaround as well. As file number increases it could require looking through 100s or 1000s of items to see if it exists. Is there really no better way to tell if the resource actually exists usingStorage.get?If anyone is using React Native, there is a work-around by checking the image’s size.
I missed that validateObjectExistence was introduced in aws-amplify 5.1.0. It works after upgrading to 5.1.0. Thanks and sorry for the confusion.
On Mon, Aug 21, 2023 at 9:12 PM Venkata Ramyasri Kota < @.***> wrote:
We have added an option
validateObjectExistenceto check for the existence of the file. Please ref doc for the usage.Any update for this issue? Currently I’m just using
fetch()method from React Native for accessing the presigned URL and make sure that response is 404 if file doesn’t exist.