Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - Français


http_upload

HTTP POST or PUT request to upload file(s) on server.

Syntax

[result, status, headers] = http_upload(url, filename, variablename)
[result, status, headers] = http_upload(url, filename, variablename, data)
[result, status, headers] = http_upload(url, filename, variablename, data, <opt_args>)

Arguments

url

A string containing the server address following by the optional port, the route of the request and query datas. syntax: "address:port/route?queryfield=querydata"

filename

A string or a matrix of string which contains local filename(s) to upload on server. The file on the server will have the same name as the local one.

A structure or a structure array with fields "local" and "remote". The field "local" contains the local filename to upload on server. The field "remote" contains a string used to set the filename on the server. When "remote" is an empty string, the local filename is used on the server.

variablename

A string which contains the file variable name expected by the server. This value must be given by the documentation of the API you are using. When a scalar string is given, the same variable name is used for all uploaded files. A matrix of string of the same size than filename argument can be given to set a specific variable name by file to upload.

data

This argument represent data sent by the request. Can be a scilab variable which will be converted into JSON format if possible or sent as a string.

<opt_args>

This represents a sequence of statements key1=value1, key2=value2, ... where key1, key2, ... can be one of the following:

headers

Strings defined as "name: value".

cookies

Strings defined as "name=value". This parameter is used to send custom cookies regardless of cookie preferences. Those cookies are sent in addition to stored cookies.

cert

This option determines whether Scilab verifies the authenticity of the peer's certificate. If none is given, no verification is performed.

Disabling verification of the certificate allows bad guys to man-in-the-middle the communication without you knowing it. Disabling verification makes the communication insecure. Just having encryption on a transfer is not enough as you cannot be sure that you are communicating with the correct end-point.

follow

By default, follow is false. Set follow=%t to follow eventual redirections.

auth

Username and password can be specified for the websites which required authentication.

The syntax is auth="username:password"

verbose

This option displays information in the Scilab console to diagnose potential network issues. It is disabled by default, set verbose=%t to display the in-progress log.

timeout

Set the maximum time in seconds that you allow the request to take. Millseconds can be set by using a floating point value. ie: 0.5 will set a timeout of 500 ms. When the timeout is reached, the function returns an error.

method

By default, this function send request a POST request. Using this argument it is possible to use a PUT request, by passing method="PUT".

result

Result is a string which contain the server answer or a Scilab variable if the answer is in JSON format.

status

HTTP response code.

headers

struct: HTTP headers of the request result.

When the optional argument follow is set to %t, all headers are returned in a list that contains one struct per request made to follow redirections.

Description

This function will perform an HTTP POST or PUT request to upload file(s).

The proxy configuration is used if it's enabled in the Preferences under the rubric "Web".

The cookies configuration under the "Web" rubric is used.

Disabled

No cookies are used and store.

Normal

Cookies are used and store. They are keeped between Scilab sessions. They are stored in SCIHOME/cookies.txt.

Private

Cookies are used and store. They are deleted at Scilab close. They are stored in TMPDIR/cookies.txt.

Examples

f1 = "myfilename";
res = http_upload("url:port/route", f1, "varname");
res = http_upload("url:port/route", f1, "varname", method="PUT");

f2 = "myfilenametwo";
res = http_upload("url:port/route", [f1 f2], "varname");

data.type = "images";
data.date = date();
res = http_upload("url:port/route", [f1 f2], "varname", data);

See also

History

VersionDescription
6.1 Function introduced.
2024.1 headers output argument added.
Report an issue
<< http_put Outils web toJSON >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:16:04 CEST 2024