Hi Seny,
We have implemented two new functions to help you insert and update files using MethodAPI - MethodAPIInsertFile and MethodAPIUpdateFile. Hopefully, it will satisfy your request to have file upload in the MethodAPI.
Here is a description on how to use it:
MethodAPIInsertFile
Overview
This API operation inserts a
single file into one or many fields of type “Picture” or “FileAttachement” into
a record of a table.
Web Service URL
https://www.methodintegration.com/MethodAPI/service.asmx
Parameters
1. strCompanyAccount – The
“Company Account” name of the registered Method Account.
2. strLogin – The “User Name”
value of the registered Method Account.
3. strPassword – The “Password”
value of the registered Method Account.
4. strSessionID – If you know
the unique current SessionID of a signed in user, you can pass this instead of
strPassword. This can be found from a Value From Session: Session ID action
from Method (especially useful if you are calling a web page or web service
from within Method).
5. strTable – The name of the
table you would like to insert into.
6. arrInsertFieldsArray – An
array containing the names of fields you wish to insert.
7. fileAttachment – A byte array
containing a file you wish insert.
Response
If
the account passes verification, and the insert successfully completes, the
returned XML response value will be “Success”.
If the request failed, the
returned XML response value will be an error message.
ASP.NET Code Example
//Read the file
into byte array
byte[ ] file = null;
FileStream fs = new FileStream("C:\\Victor\\helpIcon.png", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes =
new FileInfo("C:\\Victor\\helpIcon.png").Length;
file = br.ReadBytes((int)numBytes);
//Insert the
file into the record
string result = _methodApi.MethodAPIInsertFile("CompanyName", "UserName", "Password", "", "UploadFileTable", new string[ ] { "UploadField" }, file, "helpIcon.png");
MethodAPIUpdateFile
Overview
This API operation updates a
single file into one or many fields of type “Picture” or “FileAttachement” into
a specified table record.
Web Service URL
https://www.methodintegration.com/MethodAPI/service.asmx
Parameters
1. strCompanyAccount – The
“Company Account” name of the registered Method Account.
2. strLogin – The “User Name”
value of the registered Method Account.
3. strPassword – The “Password”
value of the registered Method Account.
4. strSessionID – If you know
the unique current SessionID of a signed in user, you can pass this instead of
strPassword. This can be found from a Value From Session: Session ID action
from Method (especially useful if you are calling a web page or web service
from within Method).
5. strTable – The name of the
table you would like to update.
6. arrUpdateFieldsArray – An
array containing the names of fields you wish to update (only fields of type “Picture”
or “FileAttachement” are allowed).
7. fileAttachment – A byte array
containing a file you wish update.
8. intRecordID - The RecordID
of record you wish to update. Every table has a unique “RecordID” field that is
used to identify each record. If you do not know the RecordID of the field, you
must search for it using a MethodAPISelect_XMLV2 or MethodAPISelect_DatasetV2
call to find it.
Response
If
the account passes verification, and the update successfully completes, the
returned XML response value will be “Success”.
If the request failed, the
returned XML response value will be an error message.
ASP.NET Code Example
//Read the file
into byte array
byte[ ] file = null;
FileStream fs = new FileStream("C:\\Victor\\helpIcon.png", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes =
new FileInfo("C:\\Victor\\helpIcon.png").Length;
file = br.ReadBytes((int)numBytes);
//Update the
file in the record
string result = _methodApi.MethodAPIUpdateFile("CompanyName", "UserName", "Password", "", "UploadFileTable", new string[ ] { "UploadField" }, file, "helpIcon.png","1");
Thank you
Victor