Example #1
0
        public async Task <MessageResponse> UploadFileHandler(Message message, object context)
        {
            try
            {
                string sourcePath     = message.Properties["path"];
                string sourceFilename = message.Properties["filename"];
                string contentType    = message.Properties["contentType"];
                string containerName  = message.Properties.ContainsKey("blobPath") ? message.Properties["blobPath"] : null;
                string targetFilename = message.Properties.ContainsKey("blobFilename") ? message.Properties["blobFilename"] : null;
                string sasUri         = message.Properties.ContainsKey("sasUri") ? message.Properties["sasUri"] : null;
                bool   append         = message.Properties.ContainsKey("append") ? Convert.ToBoolean(message.Properties["append"]) : false;

                if (sasUri == null)
                {
                    await local.UploadFile(sourcePath, sourceFilename, containerName, targetFilename, contentType, append);
                }
                else
                {
                    await local.UploadFile(sourcePath, sourceFilename, sasUri, contentType, append);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: EdgeHub-EdgeHub-UploadFileHandler '{0}'", ex.Message);
            }
            finally
            {
                ModuleClient mc = (ModuleClient)context;
                await mc.CompleteAsync(message);
            }

            return(MessageResponse.Completed);
        }
        public async Task <HttpResponseMessage> UploadFile(string path, string filename, string blobPath, string blobFilename, string contentType, bool append = false, bool deleteOnUpload = false, TimeSpan?ttl = null)
        {
            try
            {
                await local.UploadFile(path, filename, blobPath, blobFilename, contentType, deleteOnUpload, ttl, append);

                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)); //{ ReasonPhrase = ex.Message };
            }
        }