I created a folder and uploaded mp3 files:
I want to write code to find file by file name in this folder and get Wix static url of result file (like this:"
https://static.wixstatic.com/mp3/83984e_fde40985eb2147a4b72dcf31e1185f8a.mp3 ").
How can i do it? Please help me
Hi,
Select the file and on the righthand side click Copy URL
I want to do it with Wix code dynamically.
Hi @fullhouseit
As of this moment if cannot be done dynamically.
@shiran-kohai
So the following code from https://www.wix.com/corvid/reference/$w.UploadButton.html#UploadedFile
doesnt work?
$w("#myUploadButton").startUpload()
.then( (uploadedFile) => {
console.log("Upload successful. File is available here:");
console.log(uploadedFile.url);
} )
@ahmedalv94
Code example here does work, but in this case, you have a context to refer to, which is the Upload button.
What I meant was (back in May) that it is not possible to access the Media manager and get any file url.
That status has already changed (yay!) and you CAN do it now.
Please check out the API docs for wix-media-backend here .
It’s a good news. Let me check it Thank both of you.
@shiran-kohai
Following is the code I have. It uploads the file but there is nothing logged into the console
function uploadImage() {
if ($w(“#productImageUpload ”).value[0].size > 0) {
console.log(“there is image”)
$w(“#productImageUpload ”).startUpload()
.then((results) => {
console.log(“uploaded”)
console.log(results)
imageURL = results.url;
})
. catch ((uploadError) => {
let errCode = uploadError.errorCode; // 7751
let errDesc = uploadError.errorDescription; // “Error description”
});
} else {
console.log(“none”)
imageURL = $w(“#productImageUrl ”).value
}
}
@ahmedalv94
Nothing meaning not even the “there is image” or the “none” message?
Are you sure that the function is triggered?
@shiran-kohai
The function is triggered since the image gets uploaded and I can find the image in my ‘Visitor Uploads’. Btw, this is in preview mode
@ahmedalv94
Can you please add a log before the If statement and see if it is triggered.
Or if you really want to do it really programmatically:
Upload it through the mediamanager’s upload() function
https://www.wix.com/corvid/reference/wix-media-backend/mediamanager-obj/upload
which returns a Promise
/* Returns a promise that resolves to:
* {
* "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
* "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
* "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
* "sizeInBytes": 51085,
* "mimeType": "image/jpeg",
* "mediaType": "image",
* "isPrivate": false,
* "iconUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
* "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
* "originalFileName": "original-name.jpg",
* "sourceUrl": "https://somedomain.com/img/original-name.jpg",
* "width": 300,
* "height": 300,
* "labels": [
* "Blue",
* "Butterfly",
* "Turquoise"
* ],
* "opStatus": "READY"
* }
*/
You can generate the URL dynamically by using the follwing function
export function getFullDocumentURL(Document, owner) {
let strReturndoc = "";
if (Document.startsWith("wix:document:")) {
let wixDocURL = "";
wixDocURL = "https://" + owner + ".usrfiles.com/ugd/";
let wixLocalURL = "";
wixLocalURL = Document.replace('wix:document://v1/', '');
wixLocalURL = wixLocalURL.substr(0, wixLocalURL.lastIndexOf('/'));
strReturndoc = wixDocURL + wixLocalURL;
}
else {
strReturndoc = Document;
}
return strReturndoc ;
}
jlogin
December 17, 2020, 7:27am
14
Where do you get the owner value from?