javascript upload file code example
Example 1: javascript upload file button
<input id='fileid' type='file' hidden/>
<input id='buttonid' type='button' value='Upload MB' />
Example 2: javascript download file
$('a#someID').attr({target: '_blank',
href : 'http://localhost/directory/file.pdf'});
Example 3: javascript upload file button
document.getElementById('buttonid').addEventListener('click', openDialog);
function openDialog() {
document.getElementById('fileid').click();
}
Example 4: upload file from url javascript
<input type="hidden" name="image-url" value="http://books.google.com/books/content?id=L2byvgEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api">
<img src="http://books.google.com/books/content?id=L2byvgEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api"/>
Example 5: nexusjs file upload
t.field('updateProfilePic', { type: User, args: { pic: arg({ type: Upload, required: true }), }, resolve: async (root, args, context) => { const { createReadStream, mimetype, filename } = await args.pic.file // ... // ... },})
Example 6: how to use input type file and show selected file on screen
updateList = function() {
var input = document.getElementById('file');
var output = document.getElementById('fileList');
output.innerHTML = '<ul>';
for (var i = 0; i < input.files.length; ++i) {
output.innerHTML += '<li>' + input.files.item(i).name + '</li>';
}
output.innerHTML += '</ul>';
}