How to Create/Load and Download a File throught Google Drive API? - google-api

I'm trying to create a file in Google Drive through Google Drive API.I managed to create the file, but I couldn't load the attachment in the file.
To create the file I Have used this Endpoint
POST https://www.googleapis.com/upload/drive/v3/files?uploadType=media
with the Content-type : application/pdf header
And this body (but it was not taken from google => the file generated don't have a title and the description):
{
"title": "prova.pdf",
"mimeType": "application/pdf",
"description": "Stuff about the file"
}
Then I tried to load the attachment in this file (using base64 encoding)through a call to this endpoint
PATCH https://www.googleapis.com/upload/drive/v3/files/{FILEID}
with thesetwo headers:
Content-type: application/pdf
Content-Transfer-Encoding: base64
And in the body (raw - text) I put the base64 encoded file.
The call doesn't return an error but now if I open the file on the Google Drive I see the base64 string in place of the pdf file.
Then I tried downloading the file. I tried with
GET https://www.googleapis.com/drive/v2/files/{fileId}
but this call retrieves a 'webContentLink' so I have to open this link in the Browser, authenticate with my account and then the download starts.
It's possible to retrieve the document as a base64 string directly from the call?

Related

Unable to get content of file using google drive api

I am working with a react application where you can access google drive files using react-google-picker and I am using get api of google apis where you can pass "alt=media" as a URL parameter to get the file content. It's working as expected for text files but for PDF/Doc files, it returns metadata instead of actual content of file.
Is there any other way to get the content using google api's ??
this is the code for getting content of the file.
axios.get(`https://www.googleapis.com/drive/v2/files/${data.docs[0].id}?key=${developerKey}&alt=media`, {
headers: {
Authorization: Bearer ${this.state.token}
}
})

Is it possible to use a file path instead of url as `image_url` when sending a message via Slack API or Incoming Webhook?

Let's assume I have the following block which I want to send via Incoming Webhook to Slack
{
"type": "image",
"title": {
"type": "plain_text",
"text": "foo bar"
},
"image_url": "https://api.slack.com/img/blocks/example/beagle.png",
"alt_text": "foo"
}
but instead of providing a http url as image_url I would like to provide a file path because the file I want to send is in the same folder as my script.
1) Is this possible? I guess no.
2) Is it possible to upload an image via files.upload in a first step WITHOUT actually displaying is on any channel just to get the URL which then can be used as image_url?
1) No. As I mentioned earlier its not possible to use a file path to directly include an image in a message. The only way is to provide a public URL to an image file.
2) Yes, you can use files.upload you uploaded to Slack in your messages. And you do not have to share them in any channel do it.
The basic approach is:
Upload your image to Slack with files.upload. And if you do not provide any channels with that API call the file will not be shared in any channel. You will get the file object incl. the file ID of the uploaded image file.
Call files.sharedPublicURL to make that file public by providing the file ID
Your image file is now public and you can use the permalink_public of the file object to include that image in message. However, you still need to construct the direct URL for that image from the URL you get from permalink_public. Check out this post on how to get the direct URL for the image.

how to upload a.zip file in Jmeter?

I am unable to upload a .zip file from Jmeter.
Upon trying to upload the file i am getting an error like below,
{
"args":[
"unsupportedMediaType"],
"message":"Request media type is not supported",
"messageId":"unsupportedMediaType",
"correlationId":"6539cd74-5f09-473c-40d2-36f98c0a472b",
"causes":[
],
"status":415
}
HTTP Method supported: POST.
Request header:
Content-Type: application/json; charset=UTF-8
Can anyone please help me in uploading the .zip file from the Jmeter, refer to the below image for my request,
Thanks in advance.
Are you sure about your content-type and what you are doing ?
for zip content type application/json is wrong.
fileToString will try to transform byes(zip) to text which cannot work
Try
checking Use multipart/form-data for Post
and Browser compatible headers .
remove FileToString call and use last tab Files upload instead of body data. And use there the content type application/zip or something suitable
If you are trying to upload a file and send a body, you may need to use nightly build.

Getting error "the request was rejected because no multipart boundary was found" while uploading the file in Jmeter

I have tried to upload the file in jmeter:
Please find below mentioned details which i passed in request,
Http reuest:
POST: http:${server_name}/attachment
1.File Path : D:\localdrive\test_docs\images.jpg
2.Parameter Name:images.jpg
3.MIME Type:image/jpg
Http Header :
1.Accept : / ,
2.Content-Type : multipart/form-data
Response Data :
{"response":"the request was rejected because no multipart boundary was found"}
could anyone please share the solution on the same .
Got it !!!
Make sure that below parameter should be mentioned in HTTP request.
Implementation should be HttpClient3.1 or Java (Don't keep it blank)
Content encoding :UTF-8
"Use multipart/form-data for Post" in HTTP sample should be checked.
In HTTP header (Content-Type : multipart/form-data)
for Parameter-name & MIME-type
e.g. In browser enter F12 & hit the request ,
refer the content in Network tab :
Inside Param u will get request param
for example if param is :
HTML contains= Content-Disposition: form-data; name="file"; filename="images.jpg" Content-Type: image/jpeg
Then Parameter-name :file & MIME-type :image/jpeg should be like this.
& now its work fine ,That's a great relief for me !!!
also thanks Anders for ur answer.
HTML contains=
Content-Disposition: form-data; name="file";
filename="images.jpg" Content-Type: image/jpeg
So i have set =
Parameter-name :file MIME-type :image/jpeg ; In sample request i have already checked "Use multipart/form-data for Post" which i have not mentioned early.
Then also its not work ...
anything else which i missed here
There is a checkbox inside the sampler which uploads the file that says "Use multipart/form-data for Post" which needs to be checked.
If your HTML looks something like this input type="file" name="dataFile" id="fileChooser"/>" your parameter name must be "dataFile" which is the name of the input file field.
You can also use a sniffer tool like fiddler for example or the HTTP/S script recorder JMeter has to capture the request and check the MIME Type for example because I'm not sure if jpg files are "image/jpg" MIME Type
Make sure those are correctly formatted and check out what BlazeMeter says about uploading files

KendoUI Export to PDF

I am trying to make use of 'Export PDF' functionality for a KendoUI grid. The following is the code in my grid configuration:
pdf: {
allPages: true,
fileName: "feesandcosts.pdf",
proxyURL: "http://demos.telerik.com/kendo-ui/service/export"
},
When I click the 'Export PDF' button the grid grays and disables out. When I try to test the URL by navigating to it directly in the web browser it seems to be a broken hyperlink.
Can some one help guide me?
This is the description of the proxyURL from API reference. In summary is an optional setting for browsers that dont support local save of files and if you use it you should implement the functionalty.
pdf.proxyURL String (default: null)
The URL of the server side proxy which will stream the file to the end
user.
A proxy will be used when the browser isn't capable of saving files
locally e.g. Internet Explorer 9 and Safari. PDF export is not
supported in Internet Explorer 8 and below.
The developer is responsible for implementing the server-side proxy.
The proxy will receive a POST request with the following parameters in
the request body:
contentType: The MIME type of the file base64: The base-64 encoded
file content fileName: The file name, as requested by the caller. The
proxy should return the decoded file with the "Content-Disposition"
header set to attachment; filename="".

Resources