Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The following code is from this link starting on line 85. I'm a beginner in Java and Google Cloud Storage. I understand all of it except for the second parameter, "file", that is to be the byte array format. If I have a video that is 100GB what would the byte array parameter be?



 * Uploads a given file to Google Cloud Storage.
 *
 * @param filePath The desired file path for the file to be uploaded. File path should be absolute path and should include folders, sub-folders, and file name
 * @param file The file to be uploaded in byte array format
 * @return true if the file has been successfully uploaded; false otherwise
 */
public boolean uploadFile(String filePath, byte[] file) {
    try {
        setDefaultStorageCredentials();
        storage.create(BlobInfo.newBuilder(bucketName, filePath).build(),
                new ByteArrayInputStream(file));
        return true;
    } catch (Exception e) {
        return false;
    }
}


What I have tried:

I have successfully uploaded a file with a Tomcat server using the Part interface and the method getParts(). I did this to understand the upload and download procedure. GCS recommends the above code by using Blobstore.
Posted
Updated 27-Nov-18 22:51pm
v2

1 solution

Looking at the ByteArrayInputStream (Java Platform SE 7 )[^] documentation it would appear that this parameter is a staging buffer for reading the input stream. You need to provide a buffer of some number of bytes for the upload to use.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900