Skip to content
Franco Mussopower pages
Code snippet

Drag & Drop Case Attachments – Read the Files

Copy it with the button on the code. For the why and the walkthrough, see “Create a Drag and Drop experience to upload Case Attachments in Power Pages”.

Drag & Drop Case Attachments - Read the FilesJavaScript
// Retrieve the dropped files from the event object using e.originalEvent.dataTransfer.files
var files = e.originalEvent.dataTransfer.files;
 
// Loop through the files array
$.each(files, function(index, file) {
    // Initialise a new file reader
    var reader = new FileReader();
    // What to do once the 
    reader.onload = function(event) {
        // Split the file contents after the first comma (removing the base64 prefix)
        var base64 = event.target.result.split(',')[1];
        var fileName = file.name;
        var fileType = file.type;
        var fileSize = file.size;
        // Run the uploadToNoteAttachment function, passing the base64 content, the file name and the file type
        uploadToNoteAttachment(base64,fileName,fileType);
    };
    // Read the file
    reader.readAsDataURL(file);
});

Search

Book a discovery call

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