示例#1
0
        /// <summary>
        /// Upload a video to account with optional arguments
        /// </summary>
        /// <param name="uploadUrl">The url returned from /videos/create call</param>
        /// <param name="args">Optional args (video meta data)</param>
        /// <param name="filePath">Path to file to upload</param>
        /// <returns>The string response from the API call</returns>
        private string Upload(string uploadUrl, NameValueCollection args, string filePath)
        {
            _queryString = args; //no required args

            CustomWebClient client = new CustomWebClient();

            ServicePointManager.Expect100Continue = false; //upload will fail w/o

            client.Timeout     = 7200000;
            client.BaseAddress = _apiURL;
            client.QueryString = _queryString;
            client.Encoding    = UTF8Encoding.UTF8;

            WebHeaderCollection whd = new WebHeaderCollection();

            whd.Add("Content-Disposition", string.Format("attachment; filename=\"{0}\"", Path.GetFileName(filePath)));

            _queryString["api_format"] = "json";
            ConvertQueryStringsToArgs();

            string callUrl = uploadUrl + "?" + _args;

            byte[] response = client.UploadFile(callUrl, filePath);
            return(Encoding.UTF8.GetString(response));
        }
        /// <summary>
        /// Uploads the zip to the dataImportAPI
        /// </summary>
        /// <param name='zipPath'>
        /// Path to the zip file (containing data and xml configuration) to upload
        /// </param>
        /// <param name='action'>
        /// Import action.  Can be 'overwrite' or 'append'
        /// </param>
        /// <param name='runAsBackground'>
        /// determines if the SpatialKey server should return as soon as the data is uploaded 
        /// (thus freeing up your connection), or should it wait for the entire import process to complete
        /// </param>
        /// <param name='notifyByEmail'>
        /// if set as true the SpatialKey server will send an email to the authenticated user when the import is complete
        /// </param>
        /// <param name='addAllUsers'>
        /// if set as true the SpatialKey server will add the All Users group as a viewer of the dataset
        /// </param>
        public void UploadZip(string zipPath, string action = "overwrite", bool runAsBackground = true, bool notifyByEmail = false, bool addAllUsers = false)
        {
            Authenticate ();

            string path = "/SpatialKeyFramework/dataImportAPI";

            string url = String.Format ("{0}{1}{2}",
                                        _protocol,
                                        clusterHost,
                                        path,
                                        action,
                                        runAsBackground.ToString().ToLower(),
                                        notifyByEmail.ToString().ToLower(),
                                        addAllUsers.ToString().ToLower());

            Log(String.Format("UploadZip: {0} {1}", url, zipPath));

            // create the jsessionID cookie
            CookieContainer cookieJar = new CookieContainer ();
            Cookie cookie = new Cookie(_jsessionID.Name, _jsessionID.Value);
            cookieJar.Add(new Uri(String.Format("{0}{1}", _protocol, clusterHost)), cookie);

            CustomWebClient client = new CustomWebClient(cookieJar);

            // add the query string
            NameValueCollection query = new NameValueCollection();
            query.Add("action", action);
            query.Add("runAsBackground", runAsBackground.ToString().ToLower());
            query.Add("notifyByEmail", notifyByEmail.ToString().ToLower());
            query.Add("addAllUsers", addAllUsers.ToString().ToLower());
            client.QueryString = query;
            Log(NameValueCollectionToString(query));

            byte[] response = client.UploadFile(url, zipPath);
            Log(Encoding.ASCII.GetString(response));

            Log("UploadZip: Complete");
        }