cancel
Showing results for 
Search instead for 
Did you mean: 

Upload Custom Model via REST API using curl

Upload Custom Model via REST API using curl

I tried to upload my custom model via REST API with the following code:

curl -X POST 'https://mohmlovpapp01.healthgrp.com.sg/api/v2/customModels/6384510809470eaf11538486/versions/'  -H 'Content-Type: multipart/form-data' -H 'Accept: application/json' -H 'Authorization: Bearer {access-token}' -F 'filePath=rd.pkl' -F 'files=@/home/pamunixadm3001/rd.pkl' -F 'baseEnvironmentId={EnvironmentId}'

 

However, it returns the error message:

{"message": "Invalid field data", "errors": {"files": "Each file must have a corresponding filePath. Supply the files as a form-data list of `file` objects. And supply the relative file paths as a form-data list of `filePath` strings"}}

 

How do I resolve this issue? Thank you

Labels (1)
0 Kudos
2 Replies

Hi!

As it is described in the documentation:

  • file - A file with code for a custom task or a custom model. For each file supplied as form data, you must have a corresponding filePath supplied that shows the relative location of the file. For example, you have two files: /home/username/custom-task/main.py and /home/username/custom-task/helpers/helper.py. When uploading these files, you would also need to include two filePath fields of, "main.py" and "helpers/helper.py". If the supplied file already exists at the supplied filePath, the old file is replaced by the new file.
  • filePath - The local path of the file being uploaded. See the file field explanation for more details.

So I guess your parameters are confused there. Try:
-F 'filePath=@/home/pamunixadm3001/' -F 'files=rd.pkl'

0 Kudos

The error message you received indicates that each file you're trying to upload must have a corresponding filePath field, but the filePath field you provided is not being recognized. Additionally, the files field is also not recognized as expected.

To fix this issue, you can try modifying the command as follows:

[["curl -X POST 'https://mohmlovpapp01.healthgrp.com.sg/api/v2/customModels/6384510809470eaf11538486/versions/' \
-H 'Authorization: Bearer {access-token}' \
-F 'model=@rd.pkl' \
-F 'modelType=python_pkl' \
-F 'baseEnvironmentId={EnvironmentId}']]

In this modified command:

  • The model parameter is used to specify the path to the model file that you want to upload (in this case, rd.pkl).
  • The modelType parameter is used to specify the type of the model file (in this case, python_pkl).
  • The baseEnvironmentId parameter is used to specify the ID of the environment to which the model should be uploaded.

Note that you will need to replace {access-token} and {EnvironmentId} with your own values.

I hope this helps you to resolve the issue. Let me know if you have any further questions!

 

 

 

0 Kudos