Add lines to a file without overwriting google-drive sdk - google-drive-api

In the Google-Drive developers guide they show us to:
i) upload a file:
https://developers.google.com/drive/manage-uploads
ii) update a file's data:
https://developers.google.com/drive/v2/reference/files/update
The second option ii) update a file data by overwriting the file's previous data. Is there anyway I can add data to a file without overwriting it? Just add lines to a file?
Thanks.

No
The Drive API deals with files as a whole.

Related

Google App script: Overwrite existing csv file. Not create a copy using createFile

Hi I've got this Google App script that needs to overwrite a file.
At the moment it creates a copy.
Is there a line or two that can check if it exists,then delete?
Or is there an alternative to createFile that overwrites?
DriveApp.getFolderById(fold).createFile(file.getName()+'-'+sheet+'.csv', csv);
Many thanks for looking!
Filenames are not unique on Google Drive - the uniqueness of files is determined by their ID. Whereas on a regular file system, creating a file with a similar filename would erase the old file, in this case you are creating a new unique file every time.
As far as I know, the easiest way would the be to move the existing file to the trash. You can keep you existing script but add to it. Assuming your file will always exist, this should work:
const folder = DriveApp.getFolderById(fold);
folder.getFilesByName(file.getName()+'-'+sheet+'.csv').next().setTrashed(true);
folder.createFile(file.getName()+'-'+sheet+'.csv', csv);
If you are unsure that a file with that name will exist, or if there might be multiple files with that name, you will have to iterate through all them:
const folder = DriveApp.getFolderById(fold);
const files = folder.getFilesByName(file.getName()+'-'+sheet+'.csv');
while(files.hasNext()){
let f = files.next();
f.setTrashed(true);
}
folder.createFile(file.getName()+'-'+sheet+'.csv', csv);
I haven't tested this code, but it should be pretty close to what you need.
Edit
Contrary to what I said, the method DriveApp.File.setContent(content) can overwrite the content of a file. The above solution still works and avoids potential data loss.

Chrome extension how to append or edit a csv file on pc

I am able to find some information on how to read a csv file on a computer but is there any way I can modify one? In my chrome extension I need to add data to each row one at a time after scraping some websites. Is there any better way then read csv, store data as variable and rewrite is everytime? This becomes problematic when the file gets large. I am looking for a way to “append ” to a existing file or a work around. Any suggestions appreciated.
Update: From comment I see it is not possible to read from file system. But is there anyway to read from within the extension directory? How should I do so if the csv file is included with in the zip file of the extension? Can I access them somehow? Code snippets would be helpful.
I'm in the middle of creating something which might help you. Right now you can upload the CSV file and append a "modifier". You can adjust the code according to your requirement. Here's the repo https://github.com/amanrOnly/CSV_Modifier

chrome.filesystem: Rename a file and save it on the client's disk

How could I do with chrome.filesystem to rename a file and save it. For example, if my file is named myfile.txt I would rename the myfile.html and save it without using the saveAs function. And if that's not possible, do I have a solution.
The problem is that I have to save the file on the client's disk. So for me to use the filesystem functions can not be a solution, I have not seen that chrome.filesystem API that allows.
Thank you in advance! I'm a little discouraged. I also watched the browserify aside to work around the problem, but I have not found how to do it.
To rename a file you must have the ability to create a new file on the user's filesystem. You can get this permission by asking the user to open the whole directory in which the project exists. Then you can create any file you want within that directory by calling getFile with { create: true } on the resulting DirectoryEntry.
Edit: See this example for duplicating files selected by the user. Instead of using fs.root as is done here you can use the result of chrome.fileSystem.chooseEntry as the DirectoryEntry in which the file is saved.

Infusionsoft File Box - Delete File

I am new to the infusionsoft API and I am attempting to maintain some files in a Contacts' File Box...
According to the API documentation:
https://developer.infusionsoft.com/docs/read/File_Service
I can ADD a file
I can RENAME a file
I can REPLACE a file
There appears to be no way of deleting a file or getting a list of files with their details..
I want to be able to replace or delete previous file and upload a new one.
Does anyone know a way of doing this?
Thanks
Welcome to the wonderful world of the data service and interacting with tables! Specifically, you're going to want to use DataService.delete to delete the file in the database. You can also use DataService.query to get File details.
Here's an example for deleting a file, via the PHP SDK:
$file_id = 123;
$deleted = $app->dsDelete( 'FileBox', $file_id );
That's it! You can do a LOT with the Data Service.
EDIT: It looks like the FileBox table only allows Read access...Silly. Completely deleting the file via the API appears to be impossible. Gold Star, InfusionSoft.
An alternative for "deleting" a file would be to replace the file contents with an empty string. Something like:
$file_id = 123;
$deleted = $app->replaceFile( $file_id, '');
Note that this won't actually delete the file entry from the table...
There isn't a way of deleting files from the FileBox via the API. This was done intentionally to prevent files from accidentally being deleted.

Renaming file using box api v1

It's possible to rename the file while uploading to my account in box.net?
I'm using the 1.0 version and the next url:
https://upload.box.net/api/1.0/upload/myauth/myfolderid?share=1
I know it's possible to rename the file using ajax but there's nothing in the API, a option like "share" for example, to do that?
There isn't a way to rename the file and upload in the same API call in V1, but you can rename the file with a second API call: http://developers.box.net/w/page/12923947/ApiFunction_rename