Skip to content
Franco Mussopower pages
Code snippet

Upload to File column on Track record

Copy it with the button on the code. For the why and the walkthrough, see “Upload to a File column on record creation using Power Pages’ Portal Web API”.

Upload to File column on Track recordJavaScript
// Upload the file to the newly created Track record
function uploadFile(fileContent,fileName,entityID) {
    var record = {};
    record.musdyn_name = fileName;
 
    webapi.safeAjax({
        type: "PUT", // NOTE: right now Portals requires PUT instead of PATCH for the upload
        url: "/_api/musdyn_tracks(" + entityID + ")/musdyn_audiotrack?x-ms-file-name=" + fileName,
        contentType: "application/octet-stream",
        data: fileContent,
        processData: false,
        success: function (data, textStatus, xhr) {
            // Provide some visual feedback re successful upload
            $('#upload-Audio h1').html('<span style="color: #1ed760;" class="glyphicon glyphicon-ok"></span> Here\'s your audio');
            // Set the source of the hidden audio player
            audioPlayerSrcURL = '/File/download.aspx?Entity=musdyn_track' + '&Attribute=musdyn_audiotrack&Id=' + entityID;
            $('#upload-player').attr('src',audioPlayerSrcURL)
            // Show the audio player
            $('.showOnSuccess').slideDown(200);
            // Hide the form
            $('#track-content').slideUp(200);
        },
        error: function (xhr, textStatus, errorThrown) {
            // If error occurs uploading the file, provide visual feedback
            $('#upload-Audio h1').text('Uh oh, uploading file the track');
        }
    });
}

Search

Book a discovery call

30 minutes. Bring your trickiest Power Pages problem — I’ll tell you honestly whether I’m the right fit.