Method Community

 

How do I upload a file to one of my custom table fields with type "File Attachment"

Last post 09-10-2010 12:57 PM by Method_Victor. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 08-19-2010 5:28 PM

    • seny
    • Top 150 Contributor
    • Joined on 07-15-2010
    • Posts 32

    How do I upload a file to one of my custom table fields with type "File Attachment"

    I was trying to use the MethodAPI funtion MethodAPIInsertV2 to insert a record into my custom table.

    In that table, there is a field of type "File Attachment", how do I pass the file value to that function in ASP.NET C#?

    Thanks.

     

  • 08-20-2010 3:24 PM In reply to

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Hi Seny,

    I am sorry to let you know that currently we are not supporting an insert or update of files into Method tables, through means of MethodAPI. Nevertheless, we are planning to implement this feature in the near future. In the mean time, you will need to omit the “File Attachment” column and upload the files manually, using Method website.
    We will surely contact you, as soon as “File Upload” will be available through MethodAPI.

    Thank you,
    Victor

  • 09-02-2010 3:02 PM In reply to

    • seny
    • Top 150 Contributor
    • Joined on 07-15-2010
    • Posts 32

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Will you please make this feature a high priority on your list? Our client specifically asked for that functionality from us, so would you please implement that ASAP?

    Thank you so mcuh.

     

  • 09-03-2010 12:38 PM In reply to

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Hi Seny,

    We are currently working on the implementation of this feature and it should be available soon (approximately in a week).

    Thank you,

    Victor

  • 09-03-2010 12:46 PM In reply to

    • seny
    • Top 150 Contributor
    • Joined on 07-15-2010
    • Posts 32

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Super, thanks so much.

  • 09-10-2010 9:53 AM In reply to

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    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

  • 09-10-2010 11:57 AM In reply to

    • seny
    • Top 150 Contributor
    • Joined on 07-15-2010
    • Posts 32

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Thanks so much.

    I will try it out later this morning. There is another question comes into my mind, which is whether there is a way right now to retrieve the file using MethodAPI. Since I wanted to upload a file, for sure I want to retrieve the file as well.

    Or I can just use the MethodAPISelect_XMLV2 or MethodAPISelect_DatasetV2 to get the file?

     

    Thanks again for your help.

  • 09-10-2010 12:35 PM In reply to

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Hi Seny,

    In order to retrieve the file you can use MethodAPISelect_DatasetV2. Here is a sample code:

     

    DataSet ds = new DataSet();

    string result = _methodApi.MethodAPISelect_DataSetV2("CompanyName", "UserName", "Password", "", ref ds, "UploadFileTable", "UploadField, UploadFieldFileName", "RecordID=1", "", "", "");

    byte[ file = new byte[64];

    file = (byte[)ds.Tables [0].Rows [0]["UploadField"];

    string fileName = ds.Tables[0].Rows[0][" UploadFieldFileName"].ToString();

    using (BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:\" + fileName, FileMode.Create)))

    {

          binWriter.Write(file);

    }

    Thank you

    Victor

     

  • 09-10-2010 12:49 PM In reply to

    • seny
    • Top 150 Contributor
    • Joined on 07-15-2010
    • Posts 32

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    Perfect!

    That was fast. Thanks.

  • 09-10-2010 12:57 PM In reply to

    Re: How do I upload a file to one of my custom table fields with type "File Attachment"

    If you prefer MethodAPISelect_XMLV2, here is a sample code for it also:

    string result = _methodApi.MethodAPISelect_XMLV2("CompanyName ", " UserName ", "Password", "", "UploadFileTable", "UploadField,UploadFieldFileName", "RecordID=1", "", "", "");

    XDocument doc = XDocument.Parse(result);

    byte[ ] file = Convert.FromBase64String(doc.Element("MethodAPI").Element("MethodIntegration"). Element("Record").Element("UploadField").Value);

    string fileName = doc.Element("MethodAPI").Element("MethodIntegration").Element("Record") .Element("UploadFieldFileName").Value;

    using (BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:\" + fileName, FileMode.Create)))

    {

        binWriter.Write(file);

    }

     

Page 1 of 1 (10 items)