Upload Design

Format

/1/Upload/Designs/[path]?[parameters]

This method must be invoked as a POST.

The design data should be included in the payload of the http call as POST data.

Description

Uploads a design or an image file directly to the design store. An image file would be use for Autodigitize actions.

Parameters

The path cannot be empty and must specify the full path to the design to upload. If a design already exists with the specified path, it will be overwritten.

Example

/1/Upload/Designs/MyDesign.PXF

/1/Upload/Designs/MyImage.PNG

Sample C# Code


using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml.Serialization;

namespace PulseID.Toolkit.WebApi.App_Data
{
	class WebApiUpload
	{
		static void Main(string[] args)
		{
			UploadDesign(args[0], args[1]);
		}

		private static void UploadDesign(string designName, string designFile)
		{
			// Format the URL used to upload the design
			string url = String.Format("http://api.pulsemicro.com/1/Upload/Designs/{0}?format=xml", designName);

			// Create the web request, ensure to set POST
			HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(url);
			httpRequest.Method = "POST";

			// Open the file stream
			using (var fileStream = new FileStream(designFile, System.IO.FileMode.Open))
			{
				// Copy the file data to the request stream
				using (Stream requestStream = httpRequest.GetRequestStream())
				{
					fileStream.CopyTo(requestStream);
				}

				// We're done with the file, so close it
				fileStream.Close();
			}

			// Perform the upload
			using (HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse)
			{
				if (httpResponse == null)
					throw new WebException("The Web Response for a successful request is null!", WebExceptionStatus.ProtocolError);

				// Check the status code

				string responseBody = null;
				using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8))
				{
					responseBody = reader.ReadToEnd();
				}

				// Deserialize the response XML data.
				// We specified format=xml in the URL, so the response should be XML data).
				MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseBody));
				System.Xml.Serialization.XmlSerializer xmlSerializer = new XmlSerializer(typeof(UploadDesignResponse));
				UploadDesignResponse response = (UploadDesignResponse)xmlSerializer.Deserialize(stream);
				// response now contains the design information returned from the successful upload.
			}
		}
	}

	// These classes are the Upload response as an Object Model.

	[XmlRoot(Namespace = @"http://api.stitchport.com/designs/1.0/")]
	public class UploadDesignResponse
	{
		public Design Design { get; set; }
	}

	public class Design
	{
		[XmlAttribute()]
		public string Name { get; set; }
	}
}