Example #1
0
        private async void uploadPartition(UserUpload upload, String filename)
        {
            using (HttpClient client = new HttpClient())
            {
                MultipartFormDataContent form = new MultipartFormDataContent();

                form.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
                form.Add(new StringContent(upload.filename), "name");
                form.Add(new StringContent(upload.artist), "artist");
                form.Add(new StringContent(upload.priceValue), "price");
                form.Add(new StringContent(upload.difficultyValue), "difficulty");
                byte[]        pictureByte = File.ReadAllBytes(upload.picturePath);
                StreamContent picture     = new StreamContent(new MemoryStream(pictureByte));
                string        mimeType    = upload.picturePath.Substring(upload.picturePath.LastIndexOf(".") + 1);
                if (mimeType == "jpg")
                {
                    mimeType = "jpeg";
                }
                picture.Headers.ContentType = new MediaTypeHeaderValue("image/" + mimeType);
                form.Add(picture, "picture", upload.picturePath);
                byte[]        fileByte = File.ReadAllBytes(filename);
                StreamContent file     = new StreamContent(new MemoryStream(fileByte));
                file.Headers.ContentType = new MediaTypeHeaderValue("audio/mid");
                form.Add(file, "file", filename);
                StreamContent preview = new StreamContent(new MemoryStream(fileByte));
                preview.Headers.ContentType = new MediaTypeHeaderValue("audio/mid");
                form.Add(preview, "preview", filename);

                client.DefaultRequestHeaders.Add("x-access-token", login.token);
                HttpResponseMessage HtmlResponse = await client.PostAsync(eipUrl + "/songs", form);

                if (HtmlResponse.IsSuccessStatusCode)
                {
                    MessageBox.Show("The song was uploaded");
                }
                else
                {
                    string json = await HtmlResponse.Content.ReadAsStringAsync();

                    MessageBox.Show("Fail during upload: " + json);
                }
            }
        }
Example #2
0
        private void uploadPartitionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UserUpload upload = new UserUpload();

            upload.StartPosition = FormStartPosition.CenterParent;
            var    result   = upload.ShowDialog(this);
            String filename = "temp.mid";

            try
            {
                saveIncipitToTrack();
                sequencer.Sequence.Save(filename);
                if (result == DialogResult.OK)
                {
                    uploadPartition(upload, filename);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error during upload: " + exception.Message);
            }
        }