|
MemoryStream stream = new MemoryStream(byteArr);
|
|
<SfUploader ID="UploadFiles">
<UploaderEvents OnUploadStart="uploadStart"></UploaderEvents>
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings>
</SfUploader>
@code{
private void uploadStart(UploadingEventArgs args)
{
String[] splitStr = { ";base64," };
var files = args.FileData.RawFile.ToString().Split(splitStr, 2, StringSplitOptions.RemoveEmptyEntries)[1];
var byteArr = System.Convert.FromBase64String(files); // return byte array
MemoryStream stream = new MemoryStream(byteArr); // return memory stream
}
}
|
If I don't want to use a url, how could i get files ?
|
<SfUploader AutoUpload="false">
<UploaderEvents ValueChange="OnChange"></UploaderEvents>
</SfUploader>
@code {
private void OnChange(UploadChangeEventArgs args)
{
foreach (var file in args.Files)
{
var path = @"path" + file.FileInfo.Name;
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
file.Stream.WriteTo(filestream);
filestream.Close();
file.Stream.Close();
}
}
} |
Hi
Sureshkumar P,
I've been using the method you suggested and its been working great.
But i was wondering if i can do more with it,
You see, i save the path data as a string in the database,
But that works for one upload at a time.
what i now wish fornis be able to upload multple files and bind their path string values to variables and be able to save them in the database.
lets say, i want to upload 3 different images and be able to save these 3 images path string value to different variables to the database.
How can i achieve this ?
Query: lets say, i want to upload 3 different images and be able to save these 3 images path string value to different variables to the database.
In our file uploader change event handler method, we have iterated multiple files using foreach looping. So, inside the foreach looping, you can save the required file into the specific patch to achieve your requirement.
Find the code example here:
|
private void OnChange(UploadChangeEventArgs args) { foreach (var file in args.Files) { // you can save the individual file using different path as per your requirement here var path = @"path" + file.FileInfo.Name; FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write); file.Stream.WriteTo(filestream); filestream.Close(); file.Stream.Close(); } }
|
Hi
Sureshkumar ,
Thanks for your response, but i'm not so sure if youve answered what i was asking..
apparently, i give path value to a variable, lets say image1 = path then i save the value string into database,
but now i want to select and upload 3 images and for the file uploader to assign each image path to 3 variables, thus image1, image 2 and image3..
so when i save the 3 variables all saves each image path value.
how i can achieve this ?
Also,
is there a way i can change the image file name to a custom one before it's uploaded ?
Hi Boot,
As mentioned in our previous update, we have gotten the separate file value in the foreach iteration. So when saving the file into same patch you can change the specific path into the patch variable.
Find the code example here:
|
private void OnChange(UploadChangeEventArgs args) { foreach (var file in args.Files) { // get the specific image patch value and replace the image patch for the patch variable here // then upload the component. // in this loop you can get the each specific file in the file variable. var path = @"path" + file.FileInfo.Name; FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write); file.Stream.WriteTo(filestream); filestream.Close(); file.Stream.Close(); List<string> DBPathVariable = new List<string>(); DBPathVariable.Add(path); } } |
Find the sample in the attachment:
Regards,
Sureshkumar P