Password protected office files fail to upload using Attachment API - servicenow

I am using ServiceNow Attachment API - POST /now/attachment/upload. This is working fine for all file types configured in Security properties. However it does not work when an attempt is made to upload a password protected office file, say Excel for example. I have tried uploading such file/s through their REST API Explorer as well as list item form with no luck.
When upload through SN form, the error received is "File mime type does not match the file content". SN form by always posts data as "application/octet-stream" however my upload script does set proper content-types and still fails. If content-type was the problem, it shouldn't have worked for unprotected file/s too.
Update
When I try to upload using REST API Explorer, it gives error for incorrect content-type. Same file without password works well. See screen shots below:
api/now/attachment/file
api/now/attachment/upload

You can upload password protected excel files to ServiceNow. Here is a snap shot where I uploaded a password protected attachment from REST API Explorer to an incident record. The content type really does not matter.

Setting MIME Type validation to false did the trick. This was acceptable in our case because we wanted to run PowerShell script that moved (uploaded) attachments from existing system to SN as part of data migration activity. It should ideally be turn on (true).

Related

Windows Azure Blob Storage download with Shared Access Signature and CUSTOM response header

I use the Windows Azure Blob Storage to keep files there.
To download files i create urls with Shared Access Signature.
It works fine, but there is one problem.
Some files (blobs) have the header "Content-Type" set during upload and other no.
if a file has no Content-Type than on request to Azure the response will have the header Content-Type: application/octet-stream . This is exactly what i need, because in such case a browser will show "Download dialog" for a user.
But for files where this header was set on upload, it is returned and sometimes it makes a problem. For example, Content-Type: images/jpeg makes a browser to show this image, but not download it (does not show Download dialog)
So, my question is
is there a way on download with presigned url from WIndows Azure to force to use some specific response header?
I want it behave like there is no Content-Type saved for a file, even if it is saved
So, after some time browsing i finally found the documentation about it.
There are references.
https://nxt.engineering/en/blog/sas_token/
https://learn.microsoft.com/en-us/rest/api/storageservices/service-sas-examples
https://learn.microsoft.com/en-us/rest/api/storageservices/create-service-sas
For me it was needed to up the version of the API (i used the 2012 API version).
Also one useful note. It is very sensetive to a date format. The expiraton time must be in the format like "2021-11-16T04:25:00Z" .
I have added 2 new arguments
'rscd=file;%20attachment&rsct=binary&'.
and both of the must be in the signature string to sign on their correct places
So, my question is is there a way on download with presigned url from
WIndows Azure to force to use some specific response header? I want it
behave like there is no Content-Type saved for a file, even if it is
saved
Yes, you can override Content-Disposition response header in your SAS Token and the blob will be always downloaded regardless of it’s content type.
You can override this header to a value like attachment; filename=yourdesiredfilename and the blob will always be downloaded with yourdesiredfilename name.

Running Excel Scripts on Outlook Attachments then sending processed files

TL;DR: I want to extract an Excel attachment from an Outlook message, automate an Excel script on the unprocessed reports, and then send the output in a new email message.
I have reports from Amazon that I have sent to a specific email on my Outlook folder each month.
I set up Power Automate to trigger whenever an email with an attachment is received in this folder.
I want to take the attachment in this Outlook email and run an Excel script that I build on Excel Desktop (not an Excel application macro) to format the data.
And then I want to send the output/result (scripted email attachment) as the body of an email out to clients.
I've gotten the first and last parts to run, but I can't get the script to process the file, that's the phase that always breaks that automation.
Things that I think might be causing the issue:
Do I need to extract the attachment from the email and save it as a file before I can run the Excel script on it?
Does the attachment need to be saved through Share Point to be later referenced by the Excel script?
Does the script need to be on the same or different cards as previous steps?
I've seen people run the Excel script through a Scope.
I've also looked at every available YouTube video to troubleshoot this: some go over certain steps in the process, but I'm having a hard time threading everything together.
Other Things I've Tried
I also tried to build a macro that does the same thing as my Excel desktop automation, and then wrote VBA code so each time a new sheet is opened the same macro is run, processing the data. But I couldn't get it to run on any new future sheet that I open, even when writing the VBA auto-open code in Module as well as This Worksheet.
I'm open to any method that will make this work.
Get email (V2) - Message ID
#{triggerOutputs()?['body/id']}
Apply to Each - Select an output from previous steps
#{outputs('Get_email_(V2)')?['body/attachments']}
Create File - File Name
#{items('Apply_to_each')?['name']}
Create File - File Content
#{items('Apply_to_each')?['contentBytes']}
Move or rename a file - File (make sure you add .xlsx for Destination File Path)
#outputs('Create_file')?['body/Id']
Run Script - File
#outputs('Move_or_rename_a_file')?['body/Id']
Get file content - File
#outputs('Move_or_rename_a_file')?['body/Id']
Send an email (V2) - Attachments Name-1
#outputs('Move_or_rename_a_file')?['body/DisplayName']
Send an email (V2) - Attachments Content - 1
#body('Get_file_content')?['body']

anonymous download request to azure storage blob service does not download pdf with user friendly name configured during upload

The requirement is to provide a friendly file name during pdf download, to our customers with whom we have shared the azure blob download urls(blobs without SAS token).I am working on this requirement using azure emulator in my local set up. I have set the content disposition property during upload of the file and am able to see the same in the blob properties(using storage explorer) after upload but it isn't returned in the response during download. Is this the expected behaviour?
I have already tried the following suggestion:
set the DefaultServiceVersion of blob service before setting containerAcl--have set it to 2017-11-09..but still the x-ms-version returned in the download response header shows 2009-09-19 and there is no content disposition returned in the response. Have checked the property in powershell too using Get-AzStorageServiceProperty -ServiceType Blob -Context $ctx
the defaultversion is set to 2017-11-09...
cases where content disposition works:
1.When i send x-ms-version in the request header, i am able to download the pdf with the name set in the content disposition parameter of the uploaded file.
2.While using SAS token too, the content disposition parameter is used and i am able to download the file with the desired name.
I need to get this working for anonymous request.
this is what i have as of now:(PHP):
$this->blobSvc = BlobRestProxy::createBlobService($this->connectionString);
$serviceProperties = $this->blobSvc->getServiceProperties();
$serviceProperties->getValue()->setDefaultServiceVersion('2017-11-09');
$this->blobSvc->setServiceProperties($serviceProperties->getValue());
the defaultserviceversion gets set correctly. But still x-ms-version is incorrect in the response and content disposition header isnt returned during download
azure Emulator seems to have the above issue. With an actual azure account , content disposition for anonymous request works as expected.Thanks for all help.

Xamarin.Auth 1.5.0: Google Drive: Cannot Name or Update Uploaded File?

I have successfully uploaded and downloaded files and downloaded files metadata
from OneDrive and Dropbox using Xamarin.Auth 1.5. I have done all of this for Google Drive except when
I upload a file I cannot name the file (shows as Untitled) and I cannot update
the file once it is uploaded.
Below is code for uploading a file (creating) initially:
Data for the file is in stream. Scope is https://www.googleapis.com/auth/drive.
URI uri = new Uri("https://www.googleapis.com/upload/drive/v3/files?uploadType=media");
OAuth2Request requestUpload = new OAuth2Request("POST", uri, null, (Account)authAccount);
requestUpload.AddMultipartData("body", stream, "application/json", dataFileName);
var responseUpload = await requestUpload.GetResponseAsync();
To update the file, I have tried adding the fileid to the url after files (e.g. files/fileid) and
I received System.Net.HttpStatusCode.NotFound and I know that the fileid is correct because I was
able to download the file using the same fileid. With the fileid, I also tried to use method PATCH
but I received a Xamarin.Auth error.
To rename the file, I have tried using two AddMultipartData, one for data and the other for
metadata (name) with correct formatting and all of the AddMultipartData metadata is added
inside the file with the body data. I tried adding both data and metadata in one AddMultipartData
with the same result as using two.
For both rename and update, I have tried all types of combinations, e.g. different uploadTypes, without
/upload, method PUT, IDictionary parameters, just to name a few.
Does anyone know how to do this? Thanks for any help or suggestions.
Xamarin.Auth has little to do with google drive APIs. It merely gets token for you.
All I can think of is that Xamarin.Auth intercepted some exception during PATCh and re-throw as Xamarin.Auth exception.
I suggest - issue on github. And ping me in community slack.

Download build drop from hosted Team Foundation Service

Using the hosted Team Foundation Service at tfs.visualstudio.com, one has the option in a Build Definition to "Copy build output to the server" which creates a zip of the drop folder that can be downloaded over https via team web access. I really need to download this drop automatically, so I can chain input to the next stage in my build pipeline.
Unfortunately, the drop URL is not obvious, but can be created using the TfsDropDownloader.
TL;DR - I can't get the TfsDropDownloader to work, I'm hoping someone else has used this tool or a similar method to succesfully download a drop from https://tfs.visualstudio.com
Using the command line TfsDropDownloader.exe I can do this:
TfsDropDownloader.exe /c:"https://MYPROJECTNAME.visualstudio.com/DefaultCollection" /t:"ProjectName" /b:"BuildDefinitionName" /u:username /p:password
...and get an empty zip file with the correct build label name of the last successful build e.g. BuildDefinitionName_20130611.1.zip
Running the source code in the debugger, this is because the URL that is generated for downloading:
https://tflonline.visualstudio.com/DefaultCollection/_apis/resources/containers/804/drop/BuildDefinitionName_20130611.1.zip
..returns a content type of application/json, which is unsupported. This exception is swallowed by the application, but not before the empty zip file is created.
Is it possible the REST API on Team Foundation Service has changed in some way so the generated URL is no longer correct?
Note that I am using the "alternate credentials" defined on my Team Foundation Service account (i.e. not my live ID) - using anything else gets me TF30063: not authorized.
I got it working by using alternate credentials, but I also had to access the REST API via a different path.
The current TfsDropDownloader builds a URL that looks like this:
https://project.visualstudio.com/DefaultCollection/_apis/resources/containers/804/drop/BuildDefinitionName_20130611.1.zip
This returns empty JSON whenever I try to use it. I'm definitely authenticated, because if I tweak the URL to:
https://project.visualstudio.com/DefaultCollection/_apis/resources/containers/804/drop
I get a nice JSON listing of every single file in the drop, but no zip.
From spying on the SSL traffic to https://tfs.visualstudio.com with Fiddler I saw that clicking the "Download drop as zip" link I can see that there is another endpoint at:
https://project.visualstudio.com/DefaultCollection/ProjectName/_api/_build/ItemContent?buildUri=vstfs%3a%2f%2f%2fBuild%2fBuild%2f639&path=%2Fdrop
...which does give you a zip. The "vstfs%3a%2f%2f%2fBuild%2fBuild%2f639" portion is the URL encoded BuildUri.
So I've changed my version of GetServerPath in the TfsDropDownloader source to do this:
private static string GetServerPath(TfsConnection collection, IBuildDetail buildDetail)
{
var downloadPath = string.Format("{0}{1}/_api/_build/ItemContent?buildUri={2}&path=%2Fdrop",
collection.Uri,
HttpUtility.UrlPathEncode(buildDetail.TeamProject),
HttpUtility.UrlEncode(buildDetail.Uri.ToString()));
return downloadPath;
}
This works for me for the time being. Hopefully this helps someone else with the same problem!

Resources