Upload of a Local File using soavirt API

Can you provide the json request payload and headers to upload a .csv from my local environment to the Virtualize server? Assume my file is located c:/files/accounts.csv and I want to place it in /VirtualAssets/files
Thanks
JT
Comments
-
Or, alternatively, could you provide a payload for creating a CSV Datasource directly from a file in my local environment. I tried using the external ID but it didn't seem to work. Would be nice if I could reference the local .csv file and create a csv datasource with a single call. Thanks JT
0 -
Hi,
You can use the /v6/files/upload API to upload the file.
Create a REST client and do a POST to http://localhost:9080/soavirt/api/v6/files/upload?id=/VirtualAssets/files/accounts.csvIn the Payload tab select File and select your file from the file system (C:\files\accounts.csv).
The csv file needs to have a begin and end header like below:------=_Part_0_1654873968.1557780652323
Content-Disposition: form-data; name="file"
Content-Type: application/xmlcsv,data,here
------=_Part_0_1654873968.1557780652323--
0 -
I recommend taking a look at the API docs:
http://your_server:8090/soavirt/api#/files/filesPOST_uploadAs described there, the request body is of type multipart/form-data. The content of the file being upload is sent within the body of a MIME part. Other parameters like "id" and "replace" are query parameters.
To simplify making such an HTTP request, you could use a REST Client from a provisioning action, for example.
To create a CSV data source:
http://your_server:8090/soavirt/api#/csv/csvPOST0 -
The csv file needs to have a begin and end header like below:
This is not recommended. If you are using the REST Client tool then you first select "POST" on the Request tab and then "MIME Multipart" on the Payload tab. Then switch to Table view. To add a MIME part you simply click the Add button. For name, type "file" (as expected by the API) and for value pick "File" then select your CSV file. When you run the tool, all Content-Type and MIME headers are constructed automatically.
0 -
See related post: How to send file in the REST client.
0 -
Talking API here, not client. Thanks for the input though. Sounds like a file upload is needed first and then a CSV datasource correlation. JT
0 -
That's right. The POST to create and upload a file is different than the POST to create some other entity like a data source.
Concerning clients, you'll have to use some client to make this API call. You can use a REST Client tool or you can use some other client like cURL. You just have to make sure that the client is configured for multipart/form-data with the CSV configured for the first MIME part and the other parameters configured as query parameters.
0 -
After reading thru this thread, here is what I am seeing. I am using soatest to move a "tst" file and it moves the file (in my case to the soavirt server), however in CTP, it is unable to open. If I run from soavirt server and I do a inspect when running and for payload it has (------WebKitFormBoundary6yoHhUk4XQWikuot
Content-Disposition: form-data; name="file"; filename="ProducerById.tst"
Content-Type: application/octet-stream------WebKitFormBoundary6yoHhUk4XQWikuot--) which works. CURL works also. Using soatest it moves the file but is not able to open. What is the trick to move this in soatest. Sometimes it complains about "No Boundary".
0 -
Using soatest it moves the file but is not able to open. What is the trick to move this in soatest. Sometimes it complains about "No Boundary".
Did you do this with a SOAtest REST Client the exact way I described in my previous comment? This is where I wrote about selecting "POST" on the Request tab and then "MIME Multipart" on the Payload tab.
0 -
yes, It works if I use a CSV or text based file, but when I use a Parasoft "tst" file CTP is unable to open. Here is part of the request payload;
CTP
0 -
0
-
Hi,
What version of the API are you using? It might help if you constrained the REST Client to the service definition. From a constrained REST Client I see that the multipart field should be named "file" to match what the API definition requires.
0 -
V6, Here is an example of a curl command that works
0 -
In the curl command the mime part is named "file" but in the REST Client it is named "ClientSearchByFields" can you try changing the name mime part in the REST Client?
0 -
I changed it to "file" and it worked. thx
0 -
Glad it worked!
0