Exemple #1
0
        private void UploadAsset_Click(object sender, EventArgs e)
        {
            if (FileDialogName.Text != null & FileDialogName.Text != "")
            {
                if (SongName.Text != null & SongName.Text != "")
                {
                    if (AuthorName.Text != null & AuthorName.Text != "")
                    {
                        //
                        var    dic = new Dictionary <string, object>();
                        string ext = System.IO.Path.GetExtension(FileDialogName.Text).ToLower();
                        Console.WriteLine(ext);

                        if (ext != null)
                        {
                            if (ext == ".ogg" || ext == ".mp3")
                            {
                                var file = new FormUpload.FileParameter(File.ReadAllBytes(FileDialogName.Text), "asset-upload" + ext, "application/octet-stream");
                                dic.Add("SongName", SongName.Text);
                                dic.Add("Author", AuthorName.Text);
                                dic.Add("Type", ext);
                                dic.Add("Content", file);
                                Functions.UploadAsset("audio", dic);
                            }
                        }
                    }
                }
            }
        }
        public HttpWebResponse SplitPdf(String InputFilePath, String OutputFilePath, String Range)
        {
            String url = this.broker.RestEndpointURL + ":" + this.broker.RestEndpointPort + "/pdf/split";

            string CT0       = "file";
            string fullPath0 = InputFilePath; // @"C:\Users\Administrator\Desktop\Doctools\input-01.pdf";

            FormUpload.FileParameter f0 = new FormUpload.FileParameter(File.ReadAllBytes(fullPath0), Path.GetFileName(InputFilePath), "multipart/form-data");

            Dictionary <string, object> d = new Dictionary <string, object>();

            d.Add(CT0, f0);
            d.Add("range", Range);

            string          ua   = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            HttpWebResponse Resp = FormUpload.MultipartFormDataPost(url, ua, d);

            String GeneratedFileName = "";

            //Console.WriteLine("DEBUG:" + InputFilePath + "|" + OutputFilePath);
            //C:\Users\Administrator\Desktop\customers\CareFirst\Sample_Invoice_Combined_BlankPages.pdf|C:\Users\Administrator\Desktop\customers\CareFirst\Temp
            if (InputFilePath == OutputFilePath)
            {
                String RootPath           = Path.GetDirectoryName(OutputFilePath) + "\\";
                String FileNameWithoutExt = Path.GetFileNameWithoutExtension(OutputFilePath);
                String FileExtension      = Path.GetExtension(OutputFilePath);
                GeneratedFileName = RootPath + FileNameWithoutExt + "_" + Range + FileExtension;
            }
            else
            {
                String RootPath           = OutputFilePath + "\\";
                String FileNameWithoutExt = Path.GetFileNameWithoutExtension(InputFilePath);
                String FileExtension      = Path.GetExtension(InputFilePath);
                GeneratedFileName = RootPath + FileNameWithoutExt + "_" + Range + FileExtension;
            }

            //Console.WriteLine("Debug:" + GeneratedFileName);
            using (Stream output = File.OpenWrite(GeneratedFileName))
                using (Stream input = Resp.GetResponseStream())
                {
                    input.CopyTo(output);
                }


            return(Resp);
        }
        public override dynamic Call()
        {
            //Abusing dynamic a bit by initializing the WebRequest in the base class
            System.Net.WebRequest request = (System.Net.WebRequest)base.Call();
            String body = null;
            dynamic result;

            if (request.Method.Equals("POST")) {
                //Build post params to send
                //Add the return content-type here since we'll be overriding
                //the one we normally specify in the request
                this.Parameters.Add ("content-type", "text/xml");

                String filename = this.Parameters["content"];
                this.Parameters.Remove("content");

                System.IO.FileStream upload = System.IO.File.OpenRead(filename);

                string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());
                string contentType = "multipart/form-data; boundary=" + formDataBoundary;

                request.ContentType = contentType;

                Dictionary<String,Object> postParameters = new Dictionary<string, object>();

                foreach (KeyValuePair<String,String> p in this.Parameters) {
                    postParameters.Add (p.Key, p.Value);
                }

                ZipRecruiter.FormUpload.FileParameter file = new FormUpload.FileParameter(
                    new BinaryReader (upload).ReadBytes((int)upload.Length));
                file.ContentType = "text/csv";
                file.FileName = upload.Name;

                postParameters.Add ("content", file);

                byte[] formData = ZipRecruiter.FormUpload.GetMultipartFormData(postParameters, formDataBoundary);

                result = this.handle.MakeRequest(request, this.DetermineSerializationType (), formData);
            } else {
                result = this.handle.MakeRequest(request, this.DetermineSerializationType (), body);
            }

            return result;
        }
        // Transform an image PDF into a machine readable PDF
        //String PathToPdf, String OCRLanguage, String PathToJsonFile
        public HttpWebResponse GetTextInMachineReadablePDF(String InputFilePath, String Depth)
        {
            String url = this.broker.RestEndpointURL + ":" + this.broker.RestEndpointPort + "/pdf/text";

            string CT0       = "file";
            string fullPath0 = InputFilePath;

            FormUpload.FileParameter f0 = new FormUpload.FileParameter(File.ReadAllBytes(fullPath0), Path.GetFileName(InputFilePath), "multipart/form-data");

            Dictionary <string, object> d = new Dictionary <string, object>();

            d.Add(CT0, f0);
            d.Add("depth", Depth);

            string          ua   = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            HttpWebResponse Resp = FormUpload.MultipartFormDataPost(url, ua, d);

            return(Resp);
        }
        // [{  "x": 110,  "y": 710,  "width": 190,  "height": 22,  "backgroundColor": "#000000",  "opacity": 1,  "page": 1}]
        public HttpWebResponse AnnotatePdf(String InputFilePath, String OutputFilePath, String json)
        {
            String url = this.broker.RestEndpointURL + ":" + this.broker.RestEndpointPort + "/pdf/annotate";

            string CT0       = "file";
            string fullPath0 = InputFilePath;

            FormUpload.FileParameter f0 = new FormUpload.FileParameter(File.ReadAllBytes(fullPath0), Path.GetFileName(InputFilePath), "multipart/form-data");

            Dictionary <string, object> d = new Dictionary <string, object>();

            d.Add(CT0, f0);

            d.Add("json", json);

            string          ua   = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            HttpWebResponse Resp = FormUpload.MultipartFormDataPost(url, ua, d);

            String GeneratedFileName = "";

            if (InputFilePath == OutputFilePath)
            {
                String RootPath           = Path.GetDirectoryName(OutputFilePath) + "\\";
                String FileNameWithoutExt = Path.GetFileNameWithoutExtension(OutputFilePath);
                String FileExtension      = Path.GetExtension(OutputFilePath);
                GeneratedFileName = RootPath + FileNameWithoutExt + "_MR_" + FileExtension;
            }
            else
            {
                GeneratedFileName = OutputFilePath;
            }

            using (Stream output = File.OpenWrite(OutputFilePath))
                using (Stream input = Resp.GetResponseStream())
                {
                    input.CopyTo(output);
                }


            return(Resp);
        }
Exemple #6
0
        /// <summary>
        /// Sends the given storage file with the LPImageData combined to the NodeJS server
        /// </summary>
        /// <param name="storageFile"> Image file that possibly contains the license plate of a car  </param>
        /// <param name="pImageData"> This contains the location the image, lat and lon, lpImage is not used  </param>
        /// <returns>OpenAlprData that contains the detected plate from an image <see cref="OpenAlprData"/></returns>
        private OpenAlprData UseOpenAlpr(StorageFile storageFile, LPImageData pImageData)
        {
            string CT       = "file";
            string fullPath = storageFile.Path;

            FormUpload.FileParameter f = null;
            for (int i = 1; i < 10; i++)
            {
                try
                {   /*Try to read from a file until you succeed*/
                    f = new FormUpload.FileParameter(File.ReadAllBytes(fullPath), storageFile.Name, "multipart/form-data");
                    break;
                }
                catch (IOException e)
                {
                    Thread.Sleep(1000 * i);
                    Debug.WriteLine("File Load Exception OPENALPR " + i + " : " + e.ToString());
                }
            }

            /*Build the post request*/
            Dictionary <string, object> d = new Dictionary <string, object>();

            d.Add(CT, f);
            d.Add("detected_lat", pImageData.lat);
            d.Add("detected_lon", pImageData.lon);

            string ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"; /* I Don't know what this does*/
            var    wr = FormUpload.MultipartFormDataPost("http://localhost:8081/file_upload_alpr", ua, d);


            WebResponse wresp  = null;
            string      result = "";

            try
            {
                Stream       stream2 = wr.GetResponseStream();
                StreamReader reader2 = new StreamReader(stream2);
                result = reader2.ReadToEnd();
                Debug.WriteLine(string.Format("File uploaded {0}, server response is: {1}", "http://localhost:8081/file_upload_alpr", result));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error uploading file", ex);
                if (wresp != null)
                {
                    wresp.Close();
                    wresp = null;
                }
            }
            finally
            {
                wr = null;
            }
            /*Build the response as a OpenAlprData*/
            JsonObject   jsonObject;
            OpenAlprData openAlprData = new OpenAlprData();

            if (JsonObject.TryParse(result, out jsonObject))
            {
                openAlprData.Parse(jsonObject);
            }
            return(openAlprData);
        }