Greetings. I was doing a little investigating on the wix-media-backend mediaManager API and I am not getting what I think is consistent with the docs. Could someone in charge of these APIs take a look and either correct me, or correct the docs?
Thanks in advance…
At the end of this post, please look at the FileInfo object returned by getFileInfo.
First inconsistency: getFileUrl doesn’t return what the docs say it should return.
The docs for getFileUrl say:
https://www.wix.com/corvid/reference/wix-media-backend.mediaManager.html#getFileUrl
Promise
Fulfilled - The file’s URL.
/* Returns a promise that resolves to:
Looking at the FileInfo object at the end of this post, I might expect that calling this would return either the fileUrl from the Image’s FileInfo, or the Media Manager URL:
// fileUrl as returned from getFileInfo
"fileUrl": "wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg/0001_2_s.jpg#originWidth=600&originHeight=400"
// Media Manager URL provided when I open media manager and copy URL
https://static.wixstatic.com/media/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg
However, it does not. It returns something that looks like a download URL with a token:
https://download-files.wix.com/_api/download/file?downloadToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTU5NTM1MDI4OCwiZXhwIjoxNjAwNTM0Mjk4LCJqdGkiOiJkNTkwZmMxZDY5ZTMiLCJwYXlsb2FkIjp7InBhdGgiOiIvbWVkaWEvYzU2NWE0XzQwZTcxYjY1YmY2MzRiZWY5N2JkNTVkNzAwNzQ5Zjc3fm12Mi5qcGciLCJhdHRhY2htZW50Ijp7ImZpbGVuYW1lIjoiMDAwMV8yX3MuanBnIn19fQ.NJC38B5Yg0B11WTazj8ITjvozTqtqit2Wh903_s9Ei0
What is this returning? What should it return? Why doesn’t it return anything that resembles EITHER the FileInfo.fileUrl, or the Media Manager URL?
Second inconsistency: getFileInfo should work with the parameter fileUrl, but doesn’t
The docs for getFileInfo say that I should be able to use as a parameter EITHER the filename, OR the value from the collection:
Here is what the docs say:
Pass one of the following in the file parameter:
-
Media Manager file name:
-
As returned in the fileName property from the importFile() and upload() functions. Make sure to pass the file name only, without the URL and without the string “Media” in the name.
-
Wix URL:
-
As found in image type fields of database collections.
-
As returned in the fileUrl property from the importFile() and upload() functions.
When I dump the image field from my database collection (.csv dump), I see the following.
(This is also the same as what the Media Manager gives me when I open up the image and click "copy URL.)
https://static.wixstatic.com/media/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg
So, it seems like there are 2 different URLs. The Media Manager URL, and the FileInfo.fileUrl. I’m not actually sure why.
However, when I pass that value into getFileInfo, I get a 405
{"error_code":405,"error_description":"The method is not allowed for the requested URL.","error_info":null}
Likewise, when I pass in the URL as returned from getFileInfo, I get a 405. FWIW, I tried passing all the following permutations as the fileUrl:
"wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg/0001_2_s.jpg#originWidth=600&originHeight=400"
"wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg/0001_2_s.jpg"
"wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg/"
"wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg"
Here is the object that is returned from getFileInfo():
{
"fileName": "c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg",
"fileUrl": "wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg/0001_2_s.jpg#originWidth=600&originHeight=400",
"hash": "3527d5168bebda7969d67507e326de1d",
"sizeInBytes": 67023,
"mimeType": "image/jpeg",
"mediaType": "image",
"isPrivate": false,
"iconUrl": "wix:image://v1/c565a4_40e71b65bf634bef97bd55d700749f77~mv2.jpg/0001_2_s.jpg#originWidth=600&originHeight=400",
"parentFolderId": "797ef1b0d539441d9d100caf17969ef7",
"originalFileName": "0001_2_s.jpg",
"width": 600,
"height": 400,
"labels": [
"Plant",
"Flower",
"Leaf",
"Groundcover",
"Flowering plant",
"Herb",
"Leaf vegetable"
],
"opStatus": "READY"
}