Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Upload of a Local File using soavirt API

Options

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

Tagged:

Comments

  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    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

  • VirtualUser
    VirtualUser Posts: 15
    Options

    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.csv

    In 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/xml

    csv,data,here

    ------=_Part_0_1654873968.1557780652323--

  • benken_parasoft
    benken_parasoft Posts: 1,253 ✭✭✭
    edited April 2023
    Options

    I recommend taking a look at the API docs:
    http://your_server:8090/soavirt/api#/files/filesPOST_upload

    As 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/csvPOST

  • benken_parasoft
    benken_parasoft Posts: 1,253 ✭✭✭
    edited April 2023
    Options

    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.

  • benken_parasoft
    benken_parasoft Posts: 1,253 ✭✭✭
    edited April 2023
    Options
  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    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

  • benken_parasoft
    benken_parasoft Posts: 1,253 ✭✭✭
    Options

    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.