Try our conversational search powered by Generative AI!

Upload files programmatically, not available for editors

Vote:
 

Hi.

I know how to upload files programmatically with the BlobFactory.

This is my code:

var file = _contentRepository.Service.GetDefault<GenericMedia>(SiteDefinition.Current.GlobalAssetsRoot);
file.Name = createMessageFileData.FileName;

var fileExtension = createMessageFileData.FileName.Split('.');
var blob = _blobFactory.Service.CreateBlob(file.BinaryDataContainer, fileExtension[fileExtension.Length - 1]);
using (var s = blob.OpenWrite())
using (var sw = new StreamWriter(s))
{
	sw.Write(createMessageFileData.ImageData);
}
file.BinaryData = blob;
return _contentRepository.Service.Save(file, SaveAction.Publish);

At the first line, I specify where I want to store the file.

Is there any way to specify a custom place to store the files unavailable for editors?

// Anders

#83123
Mar 26, 2014 10:39
Vote:
 

Bump.

#83219
Mar 27, 2014 15:27
Vote:
 

Hi Anders,

Do you mean you want to upload the files to a folder that the Editors cannot access?

Al

#83227
Mar 27, 2014 16:52
Vote:
 

Yes. That's correct.

I want to use the Blob Storage to store files, but unavailable for editors.

#83246
Edited, Mar 28, 2014 7:47
Vote:
 

Can you upload to folder that has restricted access rights to it?

#83248
Mar 28, 2014 7:54
Vote:
 

Well... That would work. But what I really want is to upload files outside of EPiServer, but I want to use the Blob Storage since it's easy to work with and I don't want to waste time creating my own logic to upload files to the webserver.

If this isn't possible I guess it's easier to create my own logic and it will also be easier to test(?).

#83249
Mar 28, 2014 8:01
Vote:
 

Then I might use restricted folder for that - as "outside" of EPiServer using EPiServer blob storage as "proxy" is interesting case :)

If that's not a EPiServer site underneath - take care of licensing issues..

#83267
Mar 28, 2014 10:49
Vote:
 

Ok, thanks for answering. Yes, it is indeed an interesting case. Maybe it's possible to use virtual paths instead?

FYI, there is an EPiServer site underneath. I don't understand what you mean "- take care of licensing issues..".

Thanks nontheless, Valdis. :)

#83272
Mar 28, 2014 12:09
Vote:
 

I mean case when you would use just EPiServer empty site to upload files to server :)

#83280
Mar 28, 2014 13:07
Vote:
 

Maybe not best practice... But you could create your own ContentFolder programmatically under root, and mess around with that. Maybe there's a better way to do it though. Haven't worked that much with this yet.

Another tip, to get Filenames, extension etc you can use the class "Path", it has some nice static methods.. :)

 

var _contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.IContentRepository>();
        var test = _contentRepository.GetDefault<ContentFolder>(ContentReference.RootPage);
        test.Name = "Test";
        _contentRepository.Save(test, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);

    

#83607
Mar 28, 2014 15:18
Vote:
 

One way is to configure your system to have two blob providers (e.g. FileBlobProvider) with two different physical paths, the one marked as default is the one that will be used from UI etc. You can then programatically save your "hidden" files to the non-default provider by calling GetProvider in BlobFactory.

#83630
Mar 28, 2014 21:20
Vote:
 

Thanks, Johan.

This is exactly what I want. I will try it out and post my results here when I'm finished.

#83657
Edited, Mar 31, 2014 8:40
Vote:
 

Tip: You can specify a location in the FileBlobProvider constructor:

  var provider = new FileBlobProvider("c:\\mycustomlocation");

    

#83809
Mar 31, 2014 9:21
Vote:
 
#112253
Oct 27, 2014 4:42
Vote:
 

Here's the code you need to change:

            var file1 = contentRepository..GetDefault<GenericMedia>(SiteDefinition.Current.GlobalAssetsRoot);

You're setting the GlobalAssetsRoots as the parent folder. Change it to current page instead.

Regards.

/Q

#112256
Oct 27, 2014 8:09
* 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.