Ejemplo n.º 1
0
        public void FormTest()
        {
            FileStream stream = new FileStream("C:\\temp\\bodymime.mime", FileMode.Open);
            MultiPartDecoder  decoder = new MultiPartDecoder();
            var header = new ContentTypeHeader("multipart/form-data");
            header.Parameters.Add("boundary", "----WebKitFormBoundaryQsuJaNmu3FVqrYwp");
            var data = decoder.Decode(stream, header, Encoding.Default);
            if (data.Files.Count > 0)
            {
                
            }

        }
Ejemplo n.º 2
0
        // Handles receiving the actual photograph from the card.
        // data will most likely contain multipart binary post data that needs to be parsed
        private string UploadPhoto(IRequest request)
        {
            Utilities.Log("  UploadPhoto Begin", false);

            // Parse the multipart/form-data
            MultiPartDecoder decoder = new MultiPartDecoder();
            DecodedData data = decoder.Decode(request.Body, request.ContentType, request.Encoding);

            // Parse the SOAPENVELOPE using the EyeFiContentHandler()
            XDocument doc = XDocument.Parse(data.Parameters.Get("SOAPENVELOPE").Value);
            EyeFiContentHandler contentHandler = new EyeFiContentHandler(doc);

            // Get the newly uploaded file into memory
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream untrustedFile = new IsolatedStorageFileStream(data.Files["FILENAME"].TempFileName,FileMode.Open,store))
                {
                    // Integrity check the file before writing it out
                    string verifiedDigest = EyeFiCrypto.CalculateIntegrityDigest(Utilities.StreamToBytes(untrustedFile), App.ViewModel.EyeFiUploadKey);
                    string unverifiedDigest = data.Parameters.Get("INTEGRITYDIGEST").Value;

                    Utilities.Log("  Comparing my digest [" + verifiedDigest + "] to card's digest [" + unverifiedDigest + "].", false);

                    if (verifiedDigest == unverifiedDigest)
                    {
                        TarArchive tarball = TarArchive.Open(untrustedFile);
                        using (IReader reader = tarball.ExtractAllEntries())
                        {
                            while (reader.MoveToNextEntry())
                            {
                                if (!reader.Entry.IsDirectory &! reader.Entry.FilePath.Contains(".log"))
                                {
                                    string imageName = (reader.Entry.FilePath).Substring(0, reader.Entry.FilePath.IndexOf('.') + 4);
                                    string imagePath = Path.Combine(App.ViewModel.DownloadLocation, imageName);

                                    Utilities.Log("  Extracting image to " + imagePath, false);

                                    using (IsolatedStorageFileStream image = new IsolatedStorageFileStream(imagePath, FileMode.Create, store))
                                    {
                                        reader.WriteEntryTo(image);
                                    }

                                    NotifyPictureReceived(imagePath);
                                }
                            }
                        }
                        doc = EyeFiSOAPMessages.GetUploadPhotoResponseXML("true");
                        return Utilities.EncodeXml(doc, UTF8Encoding.UTF8);
                    }
                    else
                    {
                        doc = EyeFiSOAPMessages.GetUploadPhotoResponseXML("false");
                        return Utilities.EncodeXml(doc, UTF8Encoding.UTF8);
                    }
                }
            }
        }