I have a project with tons of users and their uploaded files. The database has all files available, but around a year ago, when connecting the project to Azure and migrating the files, some files were forgotten in the process. While the code now uploads files automatically to Azure when uploading them to database, trying to delete some older files cause issues.
Currently my code checks Azure deletion first and then decides on deleting the file from the database. When trying to delete a file, that doesn’t exist in Azure, I get the error message:
StorageError: The specified resource does not exist.
This means, that the current logic doesn’t delete it from the database either. I can always just ignore the error from Azure and delete it regardless, but I don’t know what would be the best and safest way to do it.
Easiest would probably be to either delete the file anyways
if (!error) {
deleteFile();
} else {
console.log("Azure failed, deleting anyways", error);
deleteFile();
}
or delete it only, if the error is the one aforementioned.
if (!error) {
deleteFile();
} else if (error.message === "The specified resource does not exist") {
console.log("Resource doesn't exist, deleting anyways", error);
deleteFile();
}
But I don’t know enough about the error message. Is there another reason to get the same error message and a possibility to delete a file in a wrong situation? Or are there other reasons this shouldn’t be done? I’ve searched the web using the error message, but found many posts regarding permissions, so could this lead to any security problems?
2
Answers
There are 2 possible reasons when you can get
StorageError: The specified resource does not exist.
:If you are not able to delete a blob for any other reasons (e.g. incorrect authorization, blob is leased etc.), you will get a different error message.
Worth knowing is that a 404 with message "The specified resource does not exist" you also get using Azurite version 3.18 released in June 2022 (https://github.com/Azure/Azurite/releases) while using table storage with the command UpsertEntityAsync:
https://github.com/Azure/Azurite/issues/1565
Unfortunately the latest, current, version of Visual studio 2022 (17.3.5) includes Azurite version 3.18 which make local usage fail.
Hopefully the latest, current, version 3.19 of Azurite from September 2022, where the issue is resolved, is bundled in later Visual studio updates.
As it is troublesome to revert to a previous version of Visual Studio I suggest you use VS Code with the plugin ‘Azurite’. You can then start Azurite from here prior to starting Visual studio to force the 3.19 version of Azurite to prevail. A non-tested approach is to start Azurite in VS Code on another port than default and then target that port specifically instead of the setting
"UseDevelopmentStorage=true"
for your table storage location.