Skip to main content

Upload image

PhenoNetAbout 2 min

Introduction

This step will guide you on how to upload images for inference. After uploading the files, the PhenoNet platform will return the parameters file_path and task_id, which serve as an identifier for inference.

Request Description

API address: https://api.phenonet.org/api/v1/openapi/upload/
Request method: HTTPS POST
Return format: JSON
Content-Type: multipart/form-data
Headers: {"accessID": {{STRING}}, "secretKey": {{STRING}}}
Body: {"file": {{BINARY_STREAM}}}

Parameter Description

parameterdata typedescriptionvaluerequired
accessIDstringaccessID is required when sending requestssee Step I: Get AI&SKTrue
secretKeystringsecretKey is required when sending requestssee Step I: Get AI&SKTrue
filebinary streamFile content binary stream, only a single image is allowed per uploading.-True

Response Description

{
    "code": "{{INTEGER}}",
    "msg": "{{STRING}}",
    "data": {
        "file_path": "{{STRING}}",
        "task_id": "{{STRING}}"
    }
}

Returned parameter description

parameterdata typedescription
codeintegerstate code
msgstringreference information
dataobjectreturned content
file_pathstringfile save path
task_idstringtask unique identification

Example Code

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests

ACCESS_ID = ''
SECRET_KEY = ''
HEADERS = {
    "accessID": ACCESS_ID,
    "secretKey": SECRET_KEY
}

def upload_file(file_path, headers):
    url = "https://api.phenonet.org/api/v1/openapi/upload/"
    try:
        with open(file_path, 'rb') as f:
            files = {'file': f}
            response = requests.post(url, headers=headers, files=files)
            response.raise_for_status()
            return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error uploading file: {e}")
        return None

if __name__ == '__main__':
    img_path = ''
    upload_res = upload_file(img_path, HEADERS)
    if upload_res:
        print(upload_res)

Error Code

codedescription
403AI (Access ID) or SK (Secret Key) error
Contributors: PhenoNet