Infusionsoft File Box - Delete File - infusionsoft

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.

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.

Store files in database with DBIC using Catalyst

I'm using Perl Catalyst framework to build an application that needs to store several files in a MySQL database (among other things). I want to store the name, path, extension, etc of the files to retrieve them later; because they are supposed to be accessible from the application (e.g: a PDF document uploaded for someone, must be available for download later). Can I do this? I found several ways to do it in PHP, but none for perl. Any ideas?
EDIT
I know I can access to some information using Catalyst::Request::Upload. I used this in the past for BLOB storage, but I dont't know how to get file information nor how to know where does catalyst store tmp files.
So, basically, the questions that arise when trying to this are:
How to know where are my files being stored once I submit them?
How to copy these files (which I assume go to a tmp folder somewhere) to a folder in my computer/server?
How to retrieve these files once I have them stored?
EDIT 2
I've checked again the documentation for Catalyst::Request::Upload (http://search.cpan.org/~jjnapiork/Catalyst-Runtime-5.90114/lib/Catalyst/Request/Upload.pm) and found out how to know where are my files being stored and how to copy them to a new non-tmp location. The only question that remains:
How do I generate a download link for these files??
The solution was pretty straight-forward.
First Make sure your 'tmp' folder is configured in the Catalyst app file (e.g: MyApp.pm).
Now, use Catalyst::Request::Upload to create the file object with the uploaded file. Sort of...
my $upload = $req->upload('input_field_name');
Now make sure you get all the data you want to store from the file. I, personally, got just the filename, MIME Type and size.
my $filename = $upload->filename;
my $size = $upload->size;
my $type = $upload->type;
Store into the database.
Now, create a folder within the public content of the page to copy the files to, and perform the copy like:
$upload->copy_to('path/to/the/public/folder');
To retrieve the files, just create a link with the base URL to the public folder and the filename you stored in the database.
Hope it helps someone... it was pretty obvious, though; but it cracked my head a little.

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.

Add lines to a file without overwriting google-drive sdk

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.

How can I add file locations to a database after they are uploaded using a Perl CGI script?

I have a CGI program I have written using Perl. One of its functions is to upload pics to the server.
All of it is working well, including adding all kinds of info to a MySQL db. My question is: How can I get the uploaded pic files location and names added to the db?
I would rather that instead of changing the script to actually upload the pics to the db. I have heard horror stories of uploading binary files to databases.
Since I am new to all of this, I am at a loss. Have tried doing some research and web searches for 3 weeks now with no luck. Any suggestions or answers would be greatly appreciated. I would really hate to have to manually add all the locations/names to the db.
I am using: a Perl CGI script, MySQL db, Linux server and the files are being uploaded to the server. I AM NOT looking to add the actual files to the db. Just their location(s).
It sounds like you have your method complete where you take the upload, make it a string and toss it unto mysql similar to reading file in as a string. However since your given a filehandle versus a filename to read by CGI. You are wondering where that file actually is.
If your using CGI.pm, the upload, uploadInfo, the param for the upload, and upload private files will help you deal with the upload file sources. Where they are stashed after the remote client and the CGI are done isn't permanent usually and a minimum is volatile.
You've got a bunch of uploaded files that need to be added to the db? Should be trivial to dash off a one-off script to loop through all the files and insert the details into the DB. If they're all in one spot, then a simple opendir()/readdir() type loop would catch them all, otherwise you can make a list of file paths to loop over and loop over that.
If you've talking about recording new uploads in the server, then it would be something along these lines:
user uploads file to server
script extracts any wanted/needed info from the file (name, size, mime-type, checksums, etc...)
start database transaction
insert file info into database
retrieve ID of new record
move uploaded file to final resting place, using the ID as its filename
if everything goes file, commit the transaction
Using the ID as the filename solves the worries of filename collisions and new uploads overwriting previous ones. And if you store the uploads somewhere outside of the site's webroot, then the only access to the files will be via your scripts, providing you with complete control over downloads.