Example #1
0
 /// <summary>
 /// add information to upload a file, also perform check of file size and file existing
 /// </summary>
 private bool AddFormFile(LibCurl.MultiPartForm mf, string fileName, string field)
 {
     if (fileName != "")
     {
         if (!DrutNETBase.FileExists(fileName))
         {
             sendLogEvent("Can't find file : " + fileName + "\n", "Curl", Enums.MessageType.Error);
             return(false);
         }
         else
         if ((new FileInfo(fileName).Length / 1024) > Enums.MAXFILESIZEKB)
         {
             sendLogEvent(fileName + " size is bigger than limit (" + (Enums.MAXFILESIZEKB / 1024).ToString() + "MB)" + "\n",
                          "Curl", Enums.MessageType.Error);
             return(false);
         }
         else
         {
             LibCurl.CURLFORMcode res = mf.AddSection(LibCurl.CURLformoption.CURLFORM_COPYNAME, field,
                                                      LibCurl.CURLformoption.CURLFORM_FILE, fileName, LibCurl.CURLformoption.CURLFORM_END);
             if (res != LibCurl.CURLFORMcode.CURL_FORMADD_OK)
             {
                 sendLogEvent("Can't add Curl file: " + res.ToString() + "\n", "Curl", Enums.MessageType.Error);
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
        private LibCurl.CURLFORMcode AddFormField(LibCurl.MultiPartForm mf, object fieldName, object Value)
        {
            LibCurl.CURLFORMcode res = mf.AddSection(LibCurl.CURLformoption.CURLFORM_COPYNAME, fieldName,
                                                     LibCurl.CURLformoption.CURLFORM_COPYCONTENTS, Value, LibCurl.CURLformoption.CURLFORM_END);

            if (res != LibCurl.CURLFORMcode.CURL_FORMADD_OK)
            {
                sendLogEvent("Can't add Curl field: " + res.ToString() + "\n", "Curl", Enums.MessageType.Error);
            }
            return(res);
        }