Is there a way to find md5sum for Google drive uploads? - google-drive-api

I have to upload some large files and folders to Google Drive. In order to make sure data is uploaded perfectly, I need to check their md5sums. Is there any other way to check uploaded files are completely uploaded?

When you upload the file the file resource is returned to you. The file resource contains a md5Checksum you should just be able to compare it with the one you have.
Try a file.list and you can see them all.
let files = Drive.Files.list();
for (item of files.items) {
Logger.log(item['md5Checksum']);
}

Related

How to get the file path for a file in google drive for use in colab?

I need the file path for a file stored in Google drive, so I can access it from a Google colab notebook.
E.g.
my_dat = ZipFile('/content/drive/MyDrive/some/file/structure/dat.zip', 'r')
Is there a quick way to "copy as path" or otherwise get the file path to the clipboard as quickly as possible from google drive?
My current method is to manually type up the file path, which is very tedious when doing it repeatedly for files deep down in directories. Basically all I need is a way to quickly and easily have 'MyDrive/some/file/structure/dat.zip' on my clipboard (e.g. similar to here), just without manually typing it.
The best way or really the only way I know of doing this using the Google drive api would be to use the
file.get method, this will return a field called parents. Once you get the parent id you can then do a file get on the parent and continue up until the parent is root. Its going to mean a lot of calls but its the only way I have found to achieve this.
I made my own library to make it easier.
!pip install kora
from kora.drive import get_path
p = get_path(file_id)

Finding a .txt file on Google Drive by name and getting its contents

I want to find text files by their name and then get their contents and make them into a var.
I have tried to find the file by its name, but it doesn't seem to work. I'm clueless as to how to find the file contents though.
My code to find the file:
function testThing() {
var findquestions = DriveApp.getFilesByName('tempquestions.txt')
Logger.log(findquestions)
}
I want it to log what it found, but the output is nothing but: "FileIterator". I don't know what that means.
As you can see in the documentation, .getFilesByName return fileiterator. What's a file iterator? The documentation states
An iterator that allows scripts to iterate over a potentially large collection of files
There may be large amount of files with the same name. This iterator provides access to all those files.
What methods provide access to file from fileIterator? This method does.
How to get contents of such file? Get blob from file and getDataAsString from blob
Logger.log(DriveApp
.getFilesByName('tempquestions.txt') //fileIterator
.next() //file(first file with that name)
.getBlob() //blob
.getDataAsString() //string
)

documents are not available after successfully uploaded to custom translator

I uploaded a zip that contains tmx files and it uploaded it successfully. I can see them in Upload History. But when I try to build a model, it's not listed in the data. I am not sure what went wrong. I see all other documents.
thanks,
--Yoshi
--Update 3/11/2019--
We've resolved the issue with TMX files uploaded within a ZIP.
--Original answer 3/8/2019--
We're investigating this issue right now. The issue is only with TMX files that are uploaded as part of a ZIP file, so for now a workaround is to upload TMX files separately. Make sure when uploading the TMX separately to check the "Override document if it exists" check box. We'll update this thread when we've shipped a fix.

Preserve fileExtension of drive file when uploading

My app loads a file from google drive. The fileExtension property is set to "peardeck" because the initial file name was "Untitled Pear Deck.peardeck". Then my user renames the file to "My Pear Deck", with no extension in the title, but the fileExtension property is still peardeck in the metadata.
BUT: when I PUT to /upload/drive/v2/files/fileID?uploadType=media, the fileExtension is cleared to "". This means that the Drive UI no longer offers to open the file with my app.
How can I stop the extension from being overwritten when I upload data to it?
Try using ?uploadType=multipart and leave the metadata portion empty. See the drive documentation for details on multipart.
My eventual solution / workaround was to forget about file extensions and rely entirely on mimetype, as pinoyyid suggested. You can use application/vnd.google.drive.ext-type.yourcustomextension if your app doesn't open one of the normal mime types.

Copy document contents in google drive api

I need to copy the content of a document into another, both stored in google drive, using Google Drive Api for Java. I'm able to upload or download documents but I don't know how directly transfer the content of a document into another one. I thought of something like that:
public void copyContent(String sourceId, String destinationId) {
File sourceFile = service.files().get(sourceId).execute();
AbstractInputStreamContent content = null; //sourceFile.getContent()??? :-(
File destinationFile = service.files().get(destinationId).execute();
service.files().update(destinationId, destinationFile, content).execute();
}
There's a way to get the file content as AbstractInputStreamContent? Or maybe it exists another approach to copy contents? I need a solution without exporting / uploading documents because I noticed some conversion problem. Thanks!
You can use the files.copy method of the Drive API to create a copy of an existing document:
https://developers.google.com/drive/v2/reference/files/copy