How to upload a csv file using Swagger Open API 3.0? - node.js

I have given the following specification for csv file upload:-
requestBody:
description: .csv file
content:
application/csv:
schema:
type: string
format: base64
I have also tried different types instead of application/csv, like multipart/form-data, text/csv etc. but none of them show a file upload option on the Swagger UI(also tried changing format to byte, binary, but no luck). The documentation mentions file upload only for images(which works fine).
Is there any way we can get the file upload option for csv or pdf files?

As of April 2020, Swagger UI shows the upload button only for application/octet-stream and image/ media types. There's an open issue to support file upload for other media types as well:
https://github.com/swagger-api/swagger-ui/issues/5636
As a workaround, you can try using application/octet-stream instead of application/csv.

Related

Downloading an image from the web and saving

I am trying to download an image from Wikipedia and save it to a file locally (using Python 3.9.x). Following this link I tried:
import urllib.request
http = 'https://en.wikipedia.org/wiki/Abacus#/media/File:Abacus_4.jpg'
urllib.request.urlretrieve(http, 'test.jpg')
However, when I try to open this file (Mac OS) I get an error: The file “test.jpg” could not be opened. It may be damaged or use a file format that Preview doesn’t recognize.
I did some more search and came across this article which suggests modifying the User-Agent. Following that I modified the above code as follows:
import urllib.request
opener=urllib.request.build_opener()
opener.addheaders=[('User-Agent','Mozilla/5.0')]
urllib.request.install_opener(opener)
http = 'https://en.wikipedia.org/wiki/Abacus#/media/File:Abacus_4.jpg'
urllib.request.urlretrieve(http, 'test.jpg')
However, modifying the User-Agent did NOT help and I still get the same error while trying to open the file: The file “test.jpg” could not be opened. It may be damaged or use a file format that Preview doesn’t recognize.
Another piece of information: the downloaded file (that does not open) is 235 KB. But if I download the image manually (Right Click -> Save Image As...) it is 455 KB.
I was wondering what else am I missing? Thank you!
The problem is, you're trying to download the web page with the .jpg format.
This link you used is actually not a photo link, but a Web site contains a photograph.
That's why the photo size is 455KB and the size of the file you're downloading is 235KB.
Instead of this :
http = 'https://en.wikipedia.org/wiki/Abacus#/media/File:Abacus_4.jpg'
urllib.request.urlretrieve(http, 'test.jpg')
Use this :
http = 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Abacus_4.jpg/800px-Abacus_4.jpg'
urllib.request.urlretrieve(http, 'test.jpg')
It is better to open any photo you want to use first with the "open image in new tab" option in your browser and then copy the url.

ibm-cos-sdk putObject does not create the correct Binary Object

Following the instructions from the documentation, I try to upload a file on a bucket.
If I upload a text file (i.e. a csv file), everything works as expected.
If I upload a binary string file (i.e. a pdf file) (read using readAsBinaryString), the file on cloud storage is wrong, only blank pages. The file size and the 256hash of the file changes.
I used all:
A buffer Buffer.from(binaryString)
A Uint8Array new TextEncoder().encode(binaryString)
A the binary string
on
putObject({
Bucket: 'test-b',
Key: key,
Body: binaryString
})
Instead of using the binary stream of the file for PDF try to upload using the multipart file upload option to upload it.

Taiko UI automation angular - Unable to use fileField to upload a csv file

Experimenting with Taiko for UI automation. Trying to upload a csv file but giving the id of the csv file selector is not working. A red rectangle outline blinks on top of the file upload link file firing {attach("/Users/username/Downloads/report.csv",$('*[id="some"]'))} but shows following error message in console.
Error: Node is not a file input element, run `.trace` for more info.
HTML
I've tried following fieldfield examples from https://docs.taiko.dev/#filefield
attach('report.csv', to(fileField('Upload CSV file (Optional)')))
fileField('Upload CSV file (Optional)').exists()
fileField({'id':'event-csv-upload'}).exists()
fileField({id:'event-csv-upload'},below('Upload CSV file (Optional)')).exists()
fileField(below('Upload CSV file (Optional)')).exists()
none of this works and finally tried following
attach("/Users/username/Downloads/report.csv",$('*[id="event-csv-upload"]'))
and
attach("/Users/username/Downloads/report.csv",fileField({id:'event-csv-upload'}))
source:https://github.com/getgauge/taiko/issues/309
Still not able to upload file using Taiko.
Why this file upload element is difficult to locate in angular code?
Is it too early to try Taiko now for angular web projects?
Do you recommend any other UI automation framework that work well with any angular versions?
attach expects a File input field as a selector to perform action on, in your case that element seems to be a hidden element linked to a button, attaching to that hidden element should work.
Try,
await attach("/Users/username/Downloads/report.csv",fileField({id:'eventCSVFileInput'},{ selectHiddenElements: true }))
Try this
await attach("/Users/username/Downloads/report.csv",fileField({id:'eventCSVFileInput'},{force:true}))

copy and decompress .tar file with Azure Data Factory

I m trying to copy and decompress .tar file from FTP to Azure Data Lake Store.
.tar file contains HTML files. In the copy activity, on a dataset, i select Compression type GZipDeflate, but I wonder what file format do I need to use? Is it supported to do such I thing without custom activity?
Unfortunately, Data factory doesn't support decompression of .tar files. The supported types for ftp are GZip, Deflate, BZip2, and ZipDeflate. (as seen here: https://learn.microsoft.com/en-us/azure/data-factory/supported-file-formats-and-compression-codecs#compression-support).
A solution may be to save the files in one of the supported formats, or try a custom activity as was explained here, although I'm not sure if it was for data factory v1 or v2: Import .tar file using Azure Data Factory
Hope this helped!
So its true that there is no way just to decompress .tar files with ADF or ADL Analytics, but there is an option to take a content from every file in .tar file and save as an output in U-SQL.
I have a scenario that I need to take content from html files inside the .tar file, so i just created html extractor that will take stream content of each html file in .tar file and save in a U-SQL output variable.
Maybe this can help someone who has a similar use case.
I used SharpCompress.dll for extracting and looping over .tar files in c#.

What does "Invalid file type chosen for conversion" mean?

A call to the Docusign API we've been using for a while (POST to /envelopes) has started returning an error sporadically:
status_code: 400
{
"errorCode": "FORMAT_CONVERSION_ERROR_INVALID_FILE_TYPE",
"message": "Invalid file type chosen for conversion."
}
What does this mean?
That should be returned when you're attempting to upload an invalid file type via the API.
What filetype were you attempting to upload? Does your filetype and contents match?
Supported File Types
DocuSign supports the following file types:
DOCUMENT .as, .asl, .asp, .doc, .docm, .docx, .dot, .dotm, .dotx, .htm, .html, .pdf, .pdx, .rtf, .txt, .wpd, .wps, .wpt
DRAWING .dwg, .dxf, .emz, .svg, .svgz, .vdx, .vsd, .vss, .vst IMAGE .bmp, .cdr, .dcx, .gif, .ico, .jpg, .jpeg, .pct, .pic, .png,
.rgb, .sam, .tga, .tif, .tiff, .wpg
PRESENTATION .dps, .dpt, .pot, .potx, .pps, .ppt, .pptm, .pptx
SPREADSHEET .csv, .et, .ett, .xls, .xlsx, .xlt
Note: DocuSign does not support macro-enabled files. To send a macro-enabled file through DocuSign, you must first convert it to PDF
format.
File size limitations
Along with the file format, DocuSign has file size limitations for
your file uploads:
MAXIMUM FILE SIZE 25 MB
RECOMMENDED SIZE 5 MB
For best performance, DocuSign recommends restricting your file
uploads to no more than 5 MB.
Source - DocuSign List of Supported File Types

Resources