Google script to move audio ".wav" files from one folder to another - javascript

So I need to move audio files that are dumped via a submission form into more specific folders. I have about 10 folders in all That I need to move them to. Here's the ask...
Collect the Audio files from the submission folder
Sort them into their appropriate folders based on key words in the file name
Here's the code I have so far.
function moveFiles(source, target) {
var sourceFolder = DriveApp.getFolderById('source');
var targetFolder = DriveApp.getFolderById('target')
var files = sourceFolder.getFilesByType(Mimetype);
while (files.hasNext()) {
var file = files.next();
targetFolder.addFile(file);
file.getParents().next().removeFile(file);
}
}
I do not know the Mimetype for audio/wav or if it is supported in google scripts.
any help is appreciated.

Related

Move submitted files in drive to another folder

I'm trying to send a submitted images to unique subfolder any time some user send images through my google form, this is my code so far :
var idnumber = Utilities.formatDate(new Date(), 'America/Bogota', 'ddMMyyyyHHmmss')
function onFormSubmit(e) {
var driveMainFolder = 'MyFolder'
var driveSubFolder = idnumber;
// Create subfolder
var parentFolder = DriveApp.getFoldersByName(driveMainFolder).next();
var newFolder = parentFolder.createFolder(driveSubFolder);
// Move files to subfolder
var files = DriveApp.getFoldersByName(driveMainFolder).next().getFiles();
while (files.hasNext()) {
var file = files.next();
var destination = DriveApp.getFoldersByName(driveSubFolder).next();
destination.addFile(file);
var pull = DriveApp.getFoldersByName(driveMainFolder).next();
pull.removeFile(file);
}
}
It kind of works, after sending the images some of these images stay in "MyFolder" instead of moving directly to the unique subfolder.
This trigger is being called in the event OnFormSubmit, is created in the Google Form Spreadsheet.
In "my Executions" the trigger doesn't display anything wrong but not the whole images moves to unique subfolder.
I'm sending 5 images, in average each one has 18kb.
Is there a way to upload images from a Google Form and add a trigger to organize the images ? Thanks !

Javascript create zip file

I am developing a website using react.js and admin-on-rest. One feature is allowing users to upload a pdf file.
I get the file as type FILE and want to get the file from FILE, compress it to zip, and then make it to type FILE.
So it should be FILE -> origin file -> zip file -> FILE from zip file.
I tried JSZip but still can not figure it out.
Any help is appreciated. Thanks
You can use JSZIP.
**use npm to install JSZIP
let zip = require('jszip')();
//hoping you have already taken input
let input = document.getElementById('fileInput'); // fileInput is id of my input element
let file = input.files[0];
let allZip = zip.file(file.name, file);
console.log(allZip)
Hi Garrick following are the steps you need to take.
1) handle fileupload in a rest wrapper
https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload
the above example is for image upload. But you will essentially be doing the same thing.
2)
const addUploadCapabilities = requestHandler => (type, resource, params) => {
if (type === 'UPDATE' && resource === 'posts') {
//use jszip to zip file here and package it however you need
// call the API with zipped file
} return requestHandler(type, resource, params);
};
There is a small app called jszip for this. Try, it would help. https://stuk.github.io/jszip/

How to access audio fle and upload to server in phonegap

i have one query like i want access to all audio file in phone gap ios and want to upload to server, so any one know how to do get all mp3 files and get upload.
we should need to create a plugin for that .
I don't think you require to create a new plugin. The existing File and File Transfer API should work in your case unless you have more requirements other than the ones stated here.
Use the file API to iterate over all the files in the app.
function success(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
//Check if the file is in mp3 format. If it is in mp3 format, trigger file upload.
}
}
function fail(error) {
alert("Failed to list directory contents: " + error.code);
}
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(success,fail);
Then use the file upload API to upload the files to the server.
var ft = new FileTransfer();
ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);

How to select Default folder location in File Upload Control?

I want to set the default path folder location has to be opened, Once I press the "browse" button in File Control. Please Help me.
This forum says it can't be done.
You are wanting to control the directory location that the browse
starts in and not the save path the file is uploaded to, correct?
I could be wrong but since the server never knows the file structure
of the client machine, the developers of that control probably did not
provide for that functionality.
COPIED: How to set physical path to upload a file in Asp.Net?
To use a folder outside of the application:
//check to make sure a file is selected
if (FileUpload1.HasFile)
{
//create the path to save the file to
string fileName = Path.Combine(#"E:\Project\Folders", FileUpload1.FileName);
//save the file to our local path
FileUpload1.SaveAs(fileName);
}
Of course, you wouldn't hardcode the path in a production application but this should save the file using the absolute path you described.
With regards to locating the file once you have saved it (per comments):
if (FileUpload1.HasFile)
{
string fileName = Path.Combine(#"E:\Project\Folders", FileUpload1.FileName);
FileUpload1.SaveAs(fileName);
FileInfo fileToDownload = new FileInfo( filename );
if (fileToDownload.Exists){
Process.Start(fileToDownload.FullName);
}
else {
MessageBox("File Not Saved!");
return;
}
}

Filesystem API - Upload from local drive to local filesystem

Ive read a lot about the filesystem API and HTML5, but i just couldn't find a working solution so i ask you guys:
I want to have a file upload form, drag drop or regular input box doesnt matter, however i want to select a file, and after uploading it should take the file or a whole folder and "upload" it to the filesystem located on the clients computer. The upload is in brackets because i actually want to copy the file/folder to the clients local file system.
Is it even possible? Because i want to make an application, where a user can upload his files such as music or large videos and movies to his local filesystem and edit/watch etc them in my application. I know i have to upload those big files i have to cut them into pieces and load them stacked up, but i just want to start little :)
Thanks in advance
There's indeed little information on this subject at the moment, so I put together an example that combines:
Using the webkitdirectory attribute on <input type="file">.
This allows the user to select a directory using an appropriate dialog box.
Using the Filesystem API.
This is about the sandboxed filesystem which allows you to store files on the client's machine.
Using the File API.
This is the API that allows you to read files. The files are accessible through an <input type="file"> element, through a transfer using drag and drop, or through the Filesystem API.
As these are currently only working nicely in Chrome, I used the webkit prefix where necessary.
http://jsfiddle.net/zLna6/3/
The code itself has comments which I hope are clear:
var fs,
err = function(e) {
throw e;
};
// request the sandboxed filesystem
webkitRequestFileSystem(
window.TEMPORARY,
5 * 1024 * 1024,
function(_fs) {
fs = _fs;
},
err
);
// when a directory is selected
$(":file").on("change", function() {
$("ul").empty();
// the selected files
var files = this.files;
if(!files) return;
// this function copies the file into the sandboxed filesystem
function save(i) {
var file = files[i];
var text = file ? file.name : "Done!";
// show the filename in the list
$("<li>").text(text).appendTo("ul");
if(!file) return;
// create a sandboxed file
fs.root.getFile(
file.name,
{ create: true },
function(fileEntry) {
// create a writer that can put data in the file
fileEntry.createWriter(function(writer) {
writer.onwriteend = function() {
// when done, continue to the next file
save(i + 1);
};
writer.onerror = err;
// this will read the contents of the current file
var fr = new FileReader;
fr.onloadend = function() {
// create a blob as that's what the
// file writer wants
var builder = new WebKitBlobBuilder;
builder.append(fr.result);
writer.write(builder.getBlob());
};
fr.onerror = err;
fr.readAsArrayBuffer(file);
}, err);
},
err
);
}
save(0);
});
$("ul").on("click", "li:not(:last)", function() {
// get the entry with this filename from the sandboxed filesystem
fs.root.getFile($(this).text(), {}, function(fileEntry) {
// get the file from the entry
fileEntry.file(function(file) {
// this will read the contents of the sandboxed file
var fr = new FileReader;
fr.onloadend = function() {
// log part of it
console.log(fr.result.slice(0, 100));
};
fr.readAsBinaryString(file);
});
}, err);
});
That is not possible, exactly, but your app can still probably work. Reading the file is possible through a file input form element, but writing the file back to disk is where you'll run into trouble.
The two ways your browser can write to disk are 1) downloading a file and 2) the HTML5 filesystem API. Option #1 obviously doesn't let your application choose the destination and option #2 only works with browser-created sandbox filesystems. That restriction might not be a deal-breaker for you -- it just means that the folders that your app uses will be buried somewhere in your browser's data files.
Also, the Filesystem API is currently Chrome-only (but it is an open standard). If you want cross-platform support, maybe you can use IndexedDB. You could use localStorage, but Chrome has a hard 5MB limit, which would be terrible for a media application.

Categories

Resources