What is the difference between blobtargetoption and blobwriteoption - google-cloud-storage

I was practicing some google cloud upload, while creating the blob I see two options to set BlobWriteOption.predefinedAcl(Storage.PredefinedAcl acl) and BlobTargetOption.predefinedAcl(Storage.PredefinedAcl acl)
I'm curious to know the difference and went through:
https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/storage/Bucket.BlobTargetOption.html
and
https://dev.ionic.com/sdk_docs/ionic_gcs_sdk/java/version_0.9.1/com/google/cloud/storage/Storage.BlobWriteOption.html
but couldn't get much difference between two.

I couldn’t find much, but it seems like the BlobWriteOption is used when input streams are involved.
For instance on this doc both methods with streams are using BlobWriteOption
public Blob create(String blob,
InputStream content,
String contentType,
Bucket.BlobWriteOption... options)
public Blob create(String blob,
InputStream content,
Bucket.BlobWriteOption... options)
As opposed to BlobTargetOption don’t have input streams
public Blob create(String blob,
byte[] content,
String contentType,
Bucket.BlobTargetOption... options)
public Blob create(String blob,
byte[] content,
Bucket.BlobTargetOption... options)
It looks like this pattern repeats on these docs as well:
https://jar-download.com/artifacts/com.google.cloud/google-cloud-storage/1.14.0/source-code/com/google/cloud/storage/Bucket.java
https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java

Related

How to add value on another section in google form in Unity3d

How can I add value on the other section on Google forms in unity3d?
I can only add values on section 1. I am having trouble on adding values on other sections.
here is the code
public GameObject username;
public GameObject email;
public GameObject phone;
public GameObject phone2;
private string Name;
private string Email;
private string Phone;
private string Phone2;
[SerializeField]
private string BASE_URL = "https://docs.google.com/forms/d/e/1FAIpQLSc8rwjEYJ0akVuuRo0GULsoyhvBxgLwuvv6oDtWiJgJZjyiMw/formResponse";
IEnumerator Post(string name, string email, string phone, string phone2) {
WWWForm form = new WWWForm();
form.AddField("entry.1417744726", name);
form.AddField("entry.881581736", email);
form.AddField("entry.977000887", phone);
form.AddField("entry.1897661126", phone2);
byte[] rawData = form.data;
WWW www = new WWW(BASE_URL, rawData);
yield return www;
}
public void Send() {
Name = username.GetComponent<InputField>().text;
Email = email.GetComponent<InputField>().text;
Phone = phone.GetComponent<InputField>().text;
Phone2 = phone2.GetComponent<InputField>().text;
StartCoroutine(Post(Name, Email, Phone, Phone2));
}
Unfortunately, it seems that this method of posting info to google forms is unreliable, as it's not well documented at all progress here is from looking at the html page code. I've followed the same tutorial and also having trouble.
But fortunately, I've found a better solution that gives you better control and access to google forms.
https://developers.google.com/apps-script/
https://developers.google.com/apps-script/reference/forms/
Instead of guessing the post API, using Google Apps Script, you can setup and deploy a web app from googles own servers in javascript, and interface with forms directly. From there you just have to design JSON payload. I got it working already using Postman to simulate the web request that will be sent from unity.
In terms of the section issue your facing, in the google apps script javascript thats not too much an issue, as the sections are just used to visually break the front end up and they don't affect the data. However they are represented as an "item" in the backend, so when you are copying the answers from the JSON payload to the form responses be mindful which index your sections are so you can skip them and not accidentally loss data.

The api server cannot create the file when receives a put request

I am new in APIs. I have a java api server. In put method on server side, i receive a string and i create a arff file using that string. then i do some process on that file and return the result which is another string.
The problem is that when i do a put request the file is not created in local path, but when i run the code on a local application for test the file is created so the code works.
I have to generate a file of that string because i am using a machine learning algorithm that only works with files.Does anyone know why is that?
the method Classify text is called in put method in server side
public static int ClassifyText(String trained_model, String text) throws FileNotFoundException, IOException, Exception {
String evaluation_file = "..\toBeClassified_text.arff";
//create a arff file for the text
FileWriter fileWriter = new FileWriter(new File(evaluation_file));
PrintWriter printWriter = new PrintWriter(fileWriter);
The problem is solved by modifiying thisline:
String evaluation_file = "D:\toBeClassified_text.arff";

415-UnSupported Media Type

While performing testing RESTFUL Web Service using POSTMAN, I encountered the below error :
415 UnSupported Media Type
Currently in my code, I'm using MediaType.TEXT_PLAIN. This is due to one of the answer from page enter link description here telling that if you need to return integer, you need to use TEXT_PLAIN.
May I know is the data that I provide in the web service is compatible with TEXT_PLAIN or not.
#POST
#Path("/post")
#Produces(MediaType.TEXT_PLAIN)
public int adaptiveAuth( #FormDataParam("uuid") String uuID,
#FormDataParam("browserinfo") String browserInfo,
#FormDataParam("ipint") long ipInt,
#FormDataParam("lat") double latiTude,
#FormDataParam("longitude") double longiTude,
#FormDataParam("sessionid") String sessionID,
#FormDataParam("spid") String spID,
#FormDataParam("tr") int tR,
#FormDataParam("jsnum") int jsNum,
#FormDataParam("fingerprint") String fingerPrint,
#FormDataParam("methodset") MethodClass[][] methodSet) throws SQLException{
The way I tested in Postman are describe as below:
Solution.
1. Remove header value in SOAP UI.
2. I was unable to process an array in Jersey. Instead of process MethodClass [][] methodSet, I'm sending the value one by one.
3. I also change back from MediaType.MULTIPART_FORM_DATA to MediaType.PLAIN_TEXT
My code is working now.
Thanks for the help.

How to get the file content type from the REST service?

I have a REST service to upload a file, is there a way to know what content type I might be getting? The user using my REST service might upload a PDF, Word or Excel document.
#POST
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Path("/details/documents")
public Response uploadDocument(#FormDataParam("file") File documentContent,
#FormDataParam("documentName") String documentName)
throws Exception {
//more implementation code here to upload the file.
}
Instead of File as a method parameter, you can use FormDataBodyPart, and then call getMediaType(). If you want to get the part's body as a File, just use getValueAs(File.class) or if you want the input stream just use InputStream.class.
#POST
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Path("/details/documents")
public Response uploadDocument(#FormDataParam("file") FormDataBodyPart part) {
MediaType mediaType = part.getMediaType();
File file = part.getValueAs(File.class);
}

Is it possible to stream data(Upload) to store on bucket of Google cloud storage and allow to download at the same time?

Is it possible to stream data(Upload) to store on bucket of Google cloud storage and allow to download at the same time?
I have tried to use the Cloud API to upload a 100MB file to the bucket by using the code as below, but during the upload, and i refresh the bucket in the Google cloud console, i cannot see the new uploading file until the upload is finished. I would like to upload realtime video encoded in H.264 to store on the Cloud storage, so the size is unknown and at the same time, other users can start downloading the file event it is uploading. So is it possible?
Test code:
File tempFile = new File("StorageSample");
RandomAccessFile raf = new RandomAccessFile(tempFile, "rw");
try
{
raf.setLength(1000 * 1000 * 100);
}
finally
{
raf.close();
}
uploadFile(TEST_FILENAME, "text/plain", tempFile, bucketName);
public static void uploadFile(
String name, String contentType, File file, String bucketName)
throws IOException, GeneralSecurityException
{
InputStreamContent contentStream = new InputStreamContent(
contentType, new FileInputStream(file));
// Setting the length improves upload performance
contentStream.setLength(file.length());
StorageObject objectMetadata = new StorageObject()
// Set the destination object name
.setName(name)
// Set the access control list to publicly read-only
.setAcl(Arrays.asList(
new ObjectAccessControl().setEntity("allAuthenticatedUsers").setRole("READER"))); //allUsers//
// Do the insert
Storage client = StorageFactory.getService();
Storage.Objects.Insert insertRequest = client.objects().insert(
bucketName, objectMetadata, contentStream);
insertRequest.getMediaHttpUploader().setDirectUploadEnabled(false);
insertRequest.execute();
}
Unfortunately it's not possible, as state in the documentation:
Objects are immutable, which means that an uploaded object cannot
change throughout its storage lifetime. An object's storage lifetime
is the time between successful object creation (upload) and successful
object deletion.
This means that an object in cloud storage starts to exist when the upload it's finished, so you cannot access the object until your upload it's not completed.