startUpload( )
Deprecated. This function will continue to work, but a newer version is available. Use the
uploadFiles()
function instead.
Description
Uploads the file that the site visitor has chosen.
The startUpload()
function triggers the upload of the file in the
upload button's value property.
Migration Instructions
If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to the new
uploadFiles()
function:
- Update your code based on the new code example.
- Test your changes to make sure your code behaves as expected.
Note the following differences between the new
uploadFiles()
function and the deprecatedstartUpload()
function:
uploadFiles()
triggers the upload of multiple files instead of a single file.uploadFiles()
returns an array ofUploadedFile
objects instead of a singleUploadFile
object.- The new
UploadedFile
object contains different properties than the deprecatedUploadFile
object.Note the following returns mapped to the
uploadFiles()
function returns as follows:
url
andmediaId
-->fileUrl
title
-->originalFileName
Syntax
function startUpload(): Promise<UploadFile>
startUpload Parameters
This function does not take any parameters.
Returns
Fulfilled - Resolves when the file upload is completed and returns an UploadFile
object.
Rejected - Rejects if the file upload fails and returns an UploadError
object, which contains the error code and description.
Return Type:
NAME
TYPE
DESCRIPTION
Wix URL of the successfully uploaded file.
Wix media ID of the uploaded file.
Title of the uploaded file.
Width of an uploaded image or video file.
Height of an uploaded image or video file.
Duration (in milliseconds) of an uploaded audio file.
Was this helpful?
This example uses a deprecated function.
12$w("#myUploadButton").startUpload()3 .then( (uploadedFile) => {4 let url = uploadedFile.url; // "wix:image://v1/68d3a9_1de7529c444b4c9eb38401f8efe0cad2.jpg/flowers.jpg#originWidth=1970&originHeight=1120"5 } )6 .catch( (uploadError) => {7 let errCode = uploadError.errorCode; // 77518 let errDesc = uploadError.errorDescription; // "Error description"9 } );10111213
This example uses a deprecated function.
This example uploads multiple files when the site visitor clicks a button. First it sets
the type of file a site visitor can choose (in this case, an image). Then the example
checks to see if the site visitor chose files using the upload button. If files were chosen, it
triggers the uploadFiles()
function and logs the status of the file upload when it completes
successfully or with an error.
12$w("#myUploadButton").fileType = "Image"; // Site visitor can choose an image3$w('#myButton').onClick( () => {4 if ($w("#myUploadButton").value.length > 0) { // Site visitor chose a file5 console.log("Uploading " + $w("#myUploadButton").value[0].name + "- Please wait.");6 $w("#myUploadButton").startUpload()7 .then( (uploadedFile) => {8 console.log("Upload successful. File is available here:");9 console.log(uploadedFile.url);10 } )11 .catch( (uploadError) => {12 console.log("File upload error: " + uploadError.errorCode);13 console.log(uploadError.errorDescription);14 } );15 }16 else { // Site visitor clicked button but didn't choose a file17 console.log("Please choose a file to upload.")18 }19} );20