Downloading native documents from Google Drive - google-api

I'd like to download files from Google Drive in their native format, using the Google Drive SDK (in order to perform some manipulation on them, and upload them back to Google Drive).
Obviously, I can use the Export Links to convert to another format (Office, etc.), but that means that the file will be converted from native to Office, and then back to native format (during upload). I'm trying to avoid this, as I expect this will not maintain 100% fidelity.
I've tried the following request:
GET /drive/v2/files/1q7BYvDDYWwXXXXXXXxIxsuby0IrXe5L4?alt=media
Authorization: Bearer ya29.XXXXXXXXXXXXXtKVg3P3zg
But the response I got was:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "The specified file does not support the requested alternate representation.",
"locationType": "parameter",
"location": "alt"
}
],
"code": 400,
"message": "The specified file does not support the requested alternate representation."
}
}
Not being able to get the content of a file in its native format is a big "hole" in the Drive API.

It's not possible to download Google Docs in their native format. Your only choice is export to HTML , Word, odt, etc and then re-import.

Related

Send pdf with smba trafficmanager or botframework

I'm trying to send pdf file as attachment proactively to teams user with https://smba.trafficmanager.net/in/v3/conversations/ and attachment format as below
"attachments": [
{
"contentType": "application/pdf",
"contentUrl": "http://www.africau.edu/images/default/sample.pdf",
"name": "sample.pdf",
"content": {
"uniqueId": "1150D938-8870-4044-9F2C-1213213123",
"fileType": "pdf"
}
}
]
I'm able to send txt files but not pdf, every time I'm getting
{"error":{"code":"BadArgument","message":"Unknown attachment type"}}
Is there any other contentType other than application/pdf ?
I agree with Hilton and Dev here. I think it's more convenient to post messages with card attachments referencing existing SharePoint files using the Microsoft Graph APIs.
MS documents referred to 2 ways for bots send attachment. Using the Microsoft Graph APIs works for bots in all scopes in Teams while using the Teams APIs works only in the personal context.
By the way, the document says pdf is ok to be a file type.
#kiran, The below payload works for me. So i am adding the payload for your convenience (below), so that you can copy/test it.
{ "body": { "contentType": "html", "content": "Here's the latest budget. <attachment id=\"153fa47d-18c9-4179-be08-9879815a9f90\"></attachment>" }, "attachments": [ { "id": "153fa47d-18c9-4179-be08-9879815a9f90", "contentType": "reference", "contentUrl": "m365x987948.sharepoint.com/sites/test/Shared%20Documents/…", "name": "Budget.pdf" } ] }
Based on the discussion in the comments, it is definitely better to rather provide a link to the document, hosted in SharePoint (files tab) - that's exactly what the Files tab is intended for, rather than every user having to download their own copy. In addition, have a look at the topic of Link Unfurling to see how to provide a better embedded experience for the posted file.

Azure IoT Edge module logs - Task upload logs failed because of error

I was following the experimental features of Built-in log pulls
https://github.com/Azure/iotedge/blob/master/doc/built-in-logs-pull.md
When I am trying to upload logs using the following payload from the azure portal(using Direct Method under each module)
PAYLOAD:
{
"schemaVersion": "1.0",
"sasUrl":"https://veeaiotcentralstorage.blob.core.windows.net/iotedgeruntimelogs/iotedgeruntimelogs.txt?sv=2019-02-02&st=2020-08-08T08%3A56%3A00Z&se=2020-08-14T08%3A56%3A00Z&sr=b&sp=rw&sig=xyz",
"items": [
{
"id": "zigbee_template-arm64v8",
"filter": {
"tail": 10
}
}
],
"encoding": "none",
"contentType": "text"
}
I am getting the error mentioned below after checking the task status
ERROR:
{"status":200,"payload":{"status":"Failed",
"message":"Task upload logs failed because of error Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.",
"correlationId":"b85002d8-d8f9-49d5-851d-9123a8d7d740"}}
Please let me know where I am having an issue
Digging into the code some more, I noticed the UploadLogs implementation doesn't create a container, but rather a folder structure within the container that you supply. As far as I can tell, the casing restriction applies when creating a blob container, but there are no such restriction on creating folders within the container.
Please check the SAS URL that you supplied, or something on the storage end. Double check that your SAS URL is generated for a pre-existing blob container.

How can I post an image to slack from a proxy?

I have an image that is hosted through a corporate proxy on a private network.
I want to post this image as an accessory on slack via a block.
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": response
},
"accessory": {
"type": "image",
"image_url": "http://unaccesible_website/files/14619.png",
"alt_text": "User's picture"
}
}
]
When I try to access this image, I get an error telling me that {'messages': ['[ERROR] downloading image failed [json-pointer:/blocks/0/accessory/image_url]']}}which I can only assume is because slack cannot access the image through the corporate proxy. (I have no problem accessing it from my browser when I am in the corporate network).
My question is, how do I tell slack to go get the image through the proxy?
I have a workaround for this right now that involves downloading the image on my local hard drive and then uploading it with files_upload, but this is slow, and stops me from using blocks (so far I haven't found a way to upload a file in a block).

How to send a local file path thorugh the QnA Create Knowledgebase API?

I am referring to this QnA create knowledgebaseAPI documentation. I want to upload the knowledge base through the Excel file which is stored in the local path. I don't have URL for the excel file, only the local path.
I followed the code given on github link, I removed the unnecessary things and kept the variable "kb" as shown below:
static string kb = $#"
{{
'name': 'VivekKB',
'qnaList': [],
'urls': [ ],
'files': [
'files': {{DBFile}}
]
}}
DBFile is the filename with full path. When I run the code, it creates an Empty knowledge store. It doesn't upload the excel file which I mentioned. Can you please help me to figure it out how to upload a local excel QnA data directly to QnA store. I want to avoid manual uploading excel to knowledgebases at https://www.qnamaker.ai.
Thanks in advance.
Vivek
Connected with the QnA team directly, asking the following:
Question: Is it possible to use a local file path to create KB through the programmatic API?
I know given in the programmatic QnA API docs it demonstrates how to add a PDF file that’s already also available online as well:
"files": [
{
"fileName": "SurfaceManual.pdf",
"fileUri": "https://download.microsoft.com/download/2/9/B/29B20383-302C-4517-A006-B0186F04BE28/surface-pro-4-user-guide-EN.pdf"
}
However when I tried using “POST Create Knowledgebase “ in Postman using the relative file path in the “fileUri”, I get “invalid uri” error.
Request Body
{
"name": "Simple QnA",
"files": [
{
"fileName": "simpleQnaSource.docx",
"fileUri": "C:\\Users\\v-asho\\Documents\\RandomWordDocs"
}
]
}
Response
{
"error": {
"code": "BadArgument",
"message": "Invalid input. See details.",
"details": [
{
"code": "ValidationFailure",
"message": "File Uri has one or more invalid uri.",
"target": "Files[0].FileUri"
}
]
}
}
Uploading the .docx file online through qnamaker.ai portal successfully creates a KB, it’s specifically through the programmatic api where I’m having issues.
QnA Team's Answer:
“fileUri” can have a publicly available and downloadable URI as value.
When using it via API, please upload the contents of local file to a publicly available domain. (Example: Azure storage blob shared to public).

Microsoft Azure Graph API download itemAttachment content

When I open email message in the office365 web browser page, there is an option to DOWNLOAD contents of the attached to this email itemAttachment ( another message attached to the current one using Microsoft Outlook ) - *.eml file, (contentType: RFC-822).
However, when I'm trying to get the contents of this itemAttachment through Graph API (same operation), the contentBytes response property is not present.
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users('bbbbb')/messages('fffff')/attachments",
"value": [{
"#odata.type": "#microsoft.graph.itemAttachment",
"id": "gggg",
"lastModifiedDateTime": "2017-02-13T16:29:45Z",
"name": "The Daily Build - Compiling your C code to .NET",
"contentType": "message/rfc822",
"size": 99129,
"isInline": false
}
]
}
Any ideas how to get contents of attached outlook message though Graph API ( contentType=itemAttachment )? The fileAttachment contentType is working fine, I can grab the contents from the contentBytes property of the Graph API response. The following API endpoints are considered:
https://graph.microsoft.com/beta/me/messages/{id}/attachments
https://graph.microsoft.com/beta/me/messages/{id}/attachments/{attachmentId}
https://graph.microsoft.com/beta/me/messages/{id}/attachments/{attachmentId}?$expand=#microsoft.graph.itemAttachment/item
neither of the above returns contents of the attached Item.
It's in beta and there isn't a documentation, but you can get MIME content with Microsoft Graph API:
GET https://graph.microsoft.com/beta/me/messages/{id}/$value
or
GET https://graph.microsoft.com/beta/users/{id | userPrincipalName}/messages/{id}/$value
Attachments:
GET https://graph.microsoft.com/beta/users/{id}/messages/{id}/attachments/{id}/$value
With the response you can create a file with .eml extension.
Edit:
Now it's officially in preview: https://learn.microsoft.com/en-us/graph/outlook-get-mime-message

Resources