Upload Storage Object

Introduction

With the Indico SDK, one can upload files to create storage objects for further consumption by other parts of the platform, creating a submission, for example.

UploadDocument

Inputs

file: Binary data of a specific file.

Outputs

Returns a list of objects, in the order of the upload, containing:

  • filename: the original file name
  • filemeta:
    • path: the storage path on Indico platform
    • name: the same original file name duplicated in this section
    • uploadType: the upload type of a storage object, almost always with the value user returned for an upload initiated from the SDK

Alternatively CreateStorageURLs can be used in place of UploadDocument where the returned result is just a list of indico storage URLs.

Try It Out

You can try out UploadDocument below.

import os
from pathlib import Path

from indico.client import IndicoClient
from indico.queries import UploadDocument

client = IndicoClient()

# Prepare files
file_names = ["my_document.pdf", "my_other_document.pdf"]
parent_path = str(Path(__file__).parent.parent / "data")
filepaths = [os.path.join(parent_path, file_name) for file_name in file_names]

# Upload files
uploaded_files = client.call(UploadDocument(files=filepaths))
using IndicoV2;

// With provided token and host
var client = new IndicoClient(token, new Uri(host));
var storageClient = client.Storage();

// Prepare files
var fileNames = new List<string> {"my_document.pdf", "my_other_document.pdf"};
var filePaths = new List<string>();
foreach (string fileName in fileNames) {
	filePaths.add("./" + fileName);
}

// Upload files
var uploadedFiles = await storageClient.UploadAsync(filePaths, default);
import com.indico.IndicoClient;
import com.indico.IndicoKtorClient;
import com.indico.storage.UploadFile;
import java.util.Arrays;
import java.util.List;
import org.json.JSONArray;

// Create client with config provided
IndicoClient client = new IndicoKtorClient(config);
UploadFile uploadFile = client.uploadFile();

// Prepare files
List<String> fileNames = Arrays.asList("my_document.pdf", "my_other_document.pdf");
List<String> filePaths = Arrays.asList();
for (fileName : fileNames) {
  	filePaths.add("./" + fileName);
}

// Upload files
JSONArray uploadedFiles = uploadFile.filePaths(filePaths).call();

What’s Next

Thinking about making a round trip? We thought the same. Check out: