Display the uploaded image in another element - filepond

How I can get the image that the user just uploaded to display in another element on the same page? I'm using the storeAsFile property within the filePond options.
As note, I'm currently displaying the image with ImagePreview plugin within the filepond input instance, but i want to show this image on another part of the page. Hope i'm being clear enough.

Found the solution,
pondPhoto.on('addfile', (error, file) => {
// this object contains the file info
console.log(file.file)
// you can construct a blob object
const imageSrc = URL.createObjectURL(file.file)
// then you may attach it to any image in your DOM
document.querySelector('img').setAttribute('src', imageSrc)
})

Related

uploading images with filepond in an express ejs project

I'm working on a project that uses express.js for backend and the ejs rendering template for frontend. I've uploaded some images using filepond and the images were converted to base64. However, while viewing the output on the browser, the images look as though they're broken (with a small square at the top-left corner).
I need help with getting this fixed. Here's the code for the function to save the images and convert to base64:
function saveCover(book, coverEncoded) {
if (coverEncoded == null) return;
const cover = coverEncoded;
if (cover != null && imageMimeTypes.includes(cover.type)) {
book.coverImage = new Buffer.from(cover.data, "base64");
book.coverImageType = cover.type;
}
}
The problem I believe will be coming from how you are retrieving the image. If the code you've shown above saves the image (i.e you are seeing some data in the database), then you should focus your attention on the code that retrieves the image to display on the webpage.

Pass Pasted Clipboard Image From CKeditor to Dropzone

We currently have code that handles all our image uploads via Dropzone.js. This includes functionality to paste from the clipboard and upload via dropzone.js, which currently works. This is that event code:
document.onpaste = function(event)
{
alert('pasted');
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) {
var item = items[index];
if (item.kind === 'file') {
// adds the file to your dropzone instance
myDropzone.addFile(item.getAsFile());
}
}
}
Following this, we have added a CKEditor (v4.10) html text editor to that page. The CKEditor has its own clipboard handling built in. If you activate the CKEditor (for example by clicking the text area), the CKEditor effectively takes control of the clipboard from that point. Which is correct, because we want the editor to be able to copy and paste text still.
However, CKEditor does not natively have image uploading built into it. It requires a plugin. But we would prefer not to use this plugin, and rather intercept the paste event, and if the data pasted is an image, pass that along to our dropzone.js handler instead.
While I am able to intercept that event, I am not sure what event data (if any) I can extract from the CKEditor paste event to pass along to the Dropzone handler. Here is the code so far:
var editor = CKEDITOR.instances.NoteText;
editor.on( 'paste', function( event )
{
alert('pasted ck');
console.dir(event);
//myDropzone.addFile(item.getAsFile());
} );
I have tried inspecting the event to see if anything is available for me to use, but don't seem to find anything.
Is what I'm trying to accomplish possible? Is it possible for me to somehow find and pass along the pasted event data from CKEditor to DropZone? Or am I going to have to implement the CKEditor image upload plugin?
Thanks.

How to save and view image in window phone 8

I a working on a simple window phone application. In which I have two filed Name and Images.
I want to save this item and want to view all saved data.
Now My query How to select images to save? and How to save images and also get images to view.
I also used PhotoChooserTask but How to save selected image and how to get saved images?
I know about how to save image file in Isolated storage. But how to save selected images and get all data?
Thanks,
Hitesh.
Thanks for your reply. I knew about photoChooserTask. I also save my image file in isolated storage. But I dont know what is the images path to save images path in database and how to display all those images in datagrid. I have a table which have fields like ID, Name and Image path. I dont know what to save in imagepath filed if I saved image in isolated storage and how to display all data in datagrid.I used following code to save data into database. IN below code please correct the image path if I was wrong.
CategoryVO newCategory = new CategoryVO()
{
Name = txtCategoryName.Text,
ImagePath = txtCategoryName.Text.Trim() + ".jpg"
};
Expdb.Category.InsertOnSubmit(newCategory);
Expdb.SubmitChanges();
Using the PhotoChooserTask you can actually launch the photo chooser application and handle the selected image.
If you want to integrate this in your application, create the instance of the PhotoChooserTask and call the Show() method. If you want to handle the user’s selection, register the Completed event which will give you handle of the chosen photo.
var photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += PhotoChooserTaskCompleted;
photoChooserTask.Show();
In the completed event implementation, you can get the chosen image as PhotoResult and set the image to your Image control or can use it in other places.
void PhotoChooserTaskCompleted(object sender, PhotoResult e)
{
switch (e.TaskResult)
{
case TaskResult.OK:
imageChooser.Source = new BitmapImage(new Uri(e.OriginalFileName));
break;
}
}
Source: http://www.codeproject.com/Articles/350126/How-to-use-the-PhotoChooserTask-to-Launch-the-Medi

Uploading single image and showing its thumbnail using jquery and asp.net mvc3

I need to upload the photo of a user with his details from asp.net mvc3 razor view. The image selected by the user has to be shown as thumbnail before submitting the form.
The model of the view contains a byte array property called Photo. On page load i am converting this byte array to base 64 string and showing it in . this is working properly .
Now i need to show the thumbnail of the image selected by the user. And when he clicks on submit button i need to bind the selected image to the model property Photo.
After googling , i came to know that showing thumbnail is not possible until I upload that image. I tried Uploadify but its UI behavior is not what i am expecting. I also tried the article http://www.dustinhorne.com/post/2011/11/16/AJAX-File-Uploads-with-jQuery-and-MVC-3.aspx, but it is also not suitable in our scenario.
can anyone help me by sharing their experience achieving this scenario.
Thanks in advance.
You could achieve this using HTML5 File API. Take a look at the following article and more specifically the Showing thumbnails of user-selected images section which illustrates an example of how you could achieve that without uploading the image to the server.
And if you want to support legacy browsers that do not yet support the HTML5 File API you could use the jQuery.form plugin which allows you to easily send the contents of a given form to the server using AJAX and it also supports file uploads. So basically you could subscribe to the .change() event of the file input or the .click() event of some see thumbnail ... button and then submit the form to a controller action using AJAX:
$('#myform').ajaxSubmit({
url: '#Url.Action("thumbnail")',
success: function(result) {
// the result variable will contain the result of
// the execution of the Thumbnail action.
// could be a BASE64 encoded representation of
// the thumbnail you generated on the server and then
// simply set it to the src property of your preview `<img>`
// element using the Data Uri scheme
}
});

How to use System.Drawing.Image in RDLC Image Control?

Is it possible to use System.Drawing.Image in an RDLC Image Control?
All I have been reading were 3 methods:
database
embeded resource
external file
Thank you thank you.
EDIT:
Following up from this .NET or C# library for CGM (Computer Graphics Metafile) format? I now got the image in System.Drawing.Image format and want to display it as part of the report (as an image) --- that's what I want to do.
Not sure if this is what you are looking for, but if you have an image in code and you want to show it in the report, create a wrapper object that has a property that returns the image as a byte array and give then an instance of this wrapper-class with the valid image to the report as a ReportDataSource.
Something like:
ReportDataSource logoDataSource = new ReportDataSource();
logoDataSource.Name = "LogoDS";
logoDataSource.Value = new List<LogoWrapper>() { yourLogoWrapper };
localReport.DataSources.Add(logoDS);
In the report you then you can the image as it were from the database
=First(Fields!LogoByteArrayProperty.Value, "LogoDS")
The wrapper looks something like:
class LogoWrapper{
...
public byte[] LogoByteArrayProperty{
get{
// Return here the image data
}
}
}
I use this quite often. It has the advantage that I don't have to add the image to the db or add it as a resource of every report. And furthermore, the app can say which image should be used.
Please note, the given image format must be known from the rdlc-engine.
The last question would be, how to convert a system.drawing.image to a byte array. I work with WPF and therefore, I dont known. But I'm sure google will respond to this question very reliable.
You Can use the 'Database' Source Option along with Parameters to Dynamically set Image Source from Byte Arrays.
Code Behind:
var param2 = new ReportParameter()
{
Name = "CompanyLogo",
Values = { Convert.ToBase64String(*ByteArrayImageObject*) }
};
ReportViewer1.LocalReport.SetParameters(param2);
rdlc File:
1- Add Text Parameters 'CompanyLogo' and 'MIMEType'
2- Set the Value Property of the Image to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)
3- Set MIME Type Property to
=Parameters!MIMEType.Value
4- Use 'Database' As Source
How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface
i am not quite sure what do you want to do with this but in general it is not possible.Image Control is just a image holder in the RDLC files.These 3 options specify the location from where the image control takes the image which to display from- database, embeded resource or external file. If you give me more info on what do you want to achieve i can give you some kind of solution.
Best Regards,
Iordan

Resources