Esempio n. 1
0
        /// <summary>
        /// Uploads a file to the image server
        /// </summary>
        /// <param name="file">the file to upload</param>
        /// <param name="fileName">the name of the file to upload</param>
        /// <param name="domain">the domain this website lives in. eg castlerockproperty, auslinkproperty etc</param>
        /// <param name="path">The path to save the image to</param>
        /// <returns>result object with filename and success / fail messages</returns>
        public IStorageItem UploadFile(Stream file, string fileName, string path)
        {
            if (fileName.Contains("."))
            {
                string[] fileNameSegments = fileName.Split('.');
                IList<string> urlSegements = new List<string>();
                foreach(string segment in fileNameSegments)
                {
                    urlSegements.Add(segment.ToUrl());
                }

                fileName = string.Join(".", urlSegements);
            }
            else
            {
                fileName = fileName.ToUrl();
            }

            CloudBlobContainer blobContainer = this.GetCloudBlobContainer();

            if (!string.IsNullOrEmpty(path) && !path.EndsWith("/"))
            {
                path += "/";
            }

            ICloudBlob blob = blobContainer.GetBlockBlobReference(path + fileName);

            blob.Properties.ContentType = this.GetContentType(fileName);
            // Create or overwrite the "myblob" blob with contents from a local file
            blob.UploadFromStream(file);

            if (!string.IsNullOrEmpty(path))
            {
                //CloudBlob cloudBlob = blobContainer.GetBlobReference(path);
                //cloudBlob.DeleteIfExists();
            }

            string host = blob.Uri.Host;
            for (int i = 0; i < 2; i++) { host += blob.Uri.Segments[i]; }

            File uploadFile = new File(this._domain, blob.Uri);
            uploadFile.Type = this.GetContentType(fileName);

            return uploadFile;
        }
Esempio n. 2
0
 public bool FileExists(File file)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
 public File GetFile(File file)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
 /// <summary>
 /// Does the file already exist in the database or not
 /// </summary>
 /// <param name="file">the to see if it already exists</param>
 private bool FileExists(File file)
 {
     return this._storageItemRepository.FileExists(file);
 }