Try our conversational search powered by Generative AI!

Edit blob Uri from Guid to filename



I wrote some code so when an editor uploads an image different sizes of the uploaded image are created and save to a blob in aws, in the format epi.fx.blob://[provider]/[container]/[blob]] 

While I can change the container portion, I am having problems figuring out how to change the blob portion of uri which is the image, to the image name plus the size it was changed to.

Any ideas on how to do this?

Sep 11, 2019 22:30

Ben, could you please share the code?

Sep 23, 2019 12:00

Hey Bartosz,

private void CreateImageInBlob(IContentMedia contentImage, string imageInfo, Stream resizedImages)
    var imageBlobContainer = _imageFile.BinaryDataContainer.Scheme + "://default/" + _imageFileName; //blob container folder name

    var blob = ServiceLocator.Current.GetInstance<IBlobFactory>().CreateBlob(new Uri(imageBlobContainer), Path.GetExtension(_imageFile.Name));

    //some code to rename image blob from GUID to image name _ image size 
    blob.Write(resizedImages); //image blob is created
    contentImage.BinaryData = blob;
    _contentRepository.Save(contentImage, SaveAction.Publish);

Is this even possible? If not, what are your recomendation to get to simillar suitable solution.

Edited, Sep 23, 2019 16:57

I was just looking at the source code last week and the blob provider creates a new Guid.NewGuid() for the filename and it is not overwritable unfortunately.  From their source

public static Uri NewBlobIdentifier(Uri container, string extension)
    Validator.ThrowIfNull("container", container);
    Validator.ThrowIfNullOrEmpty("extension", extension);
    ValidateIdentifier(container, false);
    if (Path.GetExtension(extension) != extension)
        throw new ArgumentException("Not a valid file extension", extension);
    return new Uri(container, container.AbsolutePath + "/" + GuidToUriString(Guid.NewGuid()) + extension);
Sep 23, 2019 17:25

Yep, I notice that the NewBlobIdentifier function is called when writing to a newly created blob. 

Since it was just on creation I was hoping that the name would be rewritable after, if there is no other imput I guess that is the answer, thanks.

Sep 23, 2019 18:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.