Save canvas img to server folder - image

$("#downloadPdf").click(function () {
$(".img-indicator").hide();
html2canvas($("#frame"), {
onrendered: function (canvas) {
var image = canvas.toDataURL(
'image/png');
image = image.replace('data:image/png;base64,', '');
$("#generatedImg").val(image);
window.open(image);
}
});
});
I want to save this image to folder that is located on a server,
and I want to save that image with specific file name too.

JavaScript/jQuery run on the client side and cannot access the server folders. You need to create a web page on your server that will receive the file from your JavaScript/jQuery and saves it in the folder. Then you can call this page from your JavaScript/jQuery using $.ajax.

Related

How to Dynamically bind an image from my backend server

I am currently using Vue js and trying to dynamically bind images that I'm getting from my database. I'm getting my path but the images aren't showing up. My front end is on localhost:8080 and my back end on localhost:3000.
In my app.js file, I'm establishing the the public folder as the static directory,
inside that folder I have my uploads directory which is where my images are being sent to.
app.use(express.static(path.join(__dirname, 'public')))
I'm sending my images there through multer:
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './public')
},
filename: function (req, file, cb) {
cb(null, new Date().toISOString() + file.originalname)
}
})
This is an example of how I'm seeing the image's source code popping up on the inspector.
src="public/uploads/2020-03-27T12:16:43.535Zaaa.jpeg"
I want to be able to display them dynamically in my components, but the images aren't showing up.
I'm also using Vuex and storing them in an object inside my states.
I think you should access your image using the full address
src="http://localhost:3000/uploads/2020-03-27T12:16:43.535Zaaa.jpeg"

Insert image in editor after upload

I've managed to upload images through drag & drop to a SP 2013 library by intercepting the paste and fileUploadrequest events (+ added mandatory headers and used /_api/web/getfolderbyserverrelativeurl(\'/sites/theSite/theLibrary\')/files/add(overwrite=true,%20url=\'aDynamicFilename.jpg\') as the request's URL).
The problem with this approach is that even if the image is uploaded, the image is not inserted in the editor (no error). I'm not setting config.uploadUrl for this approach.
Q#1: Is there any step which I should go through after the image is uploaded? Like telling the CKEDITOR instance to insert the image?
Later on, I've noticed that if I'm setting the config.uploadUrl to the same URL as I'm using above, the editor inserts successfully the image. The problem is that, from my trials, the config.uploadUrl is initialized together with the CKEDITOR instance (therefore, can't be assigned dynamically for each image, in case that multiple images are dragged and dropped on the editor).
Q#2: Is there another way to configure the uploadUrl or maybe some other config property that would allow the custom upload to work and insert the image in the editor?
Eventually made it work by following a similar approach as the on in this repo:
RyanSiu1995/ckeditor-ImageUploader
Use a FileReader and start loading the image when it's pasted to the
CKEditor
On the fileReader's onload event, create a img element in the
editor's document object with some opacity and with the fileReader's
Base64 string as the src
On the fileLoader's uploaded event, remove
the img and re-add it with the actual file's url (changing the src
attribute on the img was not triggering the editor's change event, which I was hooking into,so I chose to replace the whole element)
Here's the relevant section from the ckeditor-ImageUploader plugin:
fileDialog.on('change', function (e) {
var fileTools = CKEDITOR.fileTools,
uploadUrl = fileTools.getUploadUrl( editor.config, 'image' ),
file = e.target.files[0],
loader = editor.uploadRepository.create(file),
reader = new FileReader(),
notification,
img;
// verify
if (!/image/i.test(file.type)) {
notification = editor.showNotification( 'Please check the correct format.', 'warning' );
setTimeout(function() {
notification.hide()
}, 2000);
return false
}
loader.upload(uploadUrl);
// preview image
reader.readAsDataURL(e.target.files[0]);
reader.onload = function (e) {
img = editor.document.createElement('img');
img.setAttribute('src', e.target.result);
img.setStyle('opacity', 0.3);
editor.insertElement(img);
}
loader.on('uploaded', function(evt) {
editor.widgets.initOn(img, 'image', {
src: evt.sender.url
});
img.setAttribute('src', evt.sender.url);
img.setStyle('opacity', 1);
});
loader.on('error', function() {
img.$ && img.$.remove();
});
fileTools.bindNotifications(editor, loader);
// empty input
fileDialog[0].value = "";

CKFinder 3: Moving Resized Image to a destination folder

I am using CKFinder 3 intergrated with CKEditor. Now, after resizing an Image and clicking on Choose Resized, I want to move/copy the resized image to another folder using javascript. I am able to get upto the following code.
CKFinder.start({
onInit: function (finder) {
finder.on('file:choose:resizedImage', function (event) {
var file = event.data.file;
var resizedData = file.get('imageResizeData');
var resized = file.get('imageResizeData').get('resized');
// Need help here to move the resized image to another folder.
});
}
});
NOTE: I am using ASP.NET Connector.
You can use command:send request to send CopyFiles request:
https://docs-old.ckeditor.com/ckfinder3/#!/api/CKFinder.Application-request-command_send
Parameters taken by CopyFiles can be found here:
https://docs-old.ckeditor.com/ckfinder3-net/commands.html#command_copyfiles

User generated image hosting for angularJS App

I'm building a web app with AngularJS that will allow users to upload their own images. Right now all of my data is text based, so I am storing the text based data in Firebase. As far as I know, Firebase can't store images. What I want to do is store the user generated images somewhere simple (I'm thinking Amazon S3 or even Dropbox) and then reference the images via unique URLs, which I would store as text in Firebase.
My questions:
Does this seem like a valid approach?
Any recommended services for hosting the images?
How to upload an image to the hosting service and get the image's unique URL?
Right now I am allowing users to upload images on the front end with the following code, just not sure what to do with the images once I have them. Would appreciate any help, I'm very new to this!
HTML
<output id="list"></output>
<input type="file" id="files" name="files[]" class="button" multiple />
Upload Pictures</i>
Angular Controller
$scope.getImages = function(){
$("input[type='file']").trigger('click');
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
console.log(f);
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
You could use a service like Cloudinary to host images uploaded by your users. There are Angular directives that making using the service pretty easy. You will need a small server-side component to encrypt the upload parameters.
Look into Zapier integration with S3. The idea is that you setup a queue collection in firebase where you would create a new instance with the binary of the file data. Then zapier listens to for child_added on this queue collection and does it's magic (that you don't have to worry about) to upload your file to S3 bucket. After everything is finished, the instance in the queue is deleted... No server side needed with that, except there might be some fees...
Here is the link https://zapier.com/zapbook/amazon-s3/

Meteor Image Display Not Working Once App Is Deployed

Currently I am creating an application where I display an uploaded file from CollectionFS and display it using the CollectionFS url return. Locally the image loads and is displayed. However once I deploy the application to meteor.com the image url does not work. With the console indicating that the image path cannot be found.
CollectionFS returns this url for my image:
/cfs/contacts/75erhMtuwjn66fQH3_default1.png
Locally when I deploy the app I can see the image using in my .html:
img src="/cfs/contacts/75erhMtuwjn66fQH3_default1.png"
The specific code returned by CollectionFS is in the .html file and is being called client side:
{{cfsFileUrl "defaultHandler" fileId=fileId collection="Collection"}}
Locally I use this address as the source for the uploaded image in my html:
localhost:port/cfs/contacts/75erhMtuwjn66fQH3_default1.png
But when I attempt to view the image of the deployed app using the same procedure, it returns with an error of url not found:
http://host.meteor/cfs/contacts/75erhMtuwjn66fQH3_default1.png.com
A file is added on a click event client side .js:
'change .fileUploader': function (e) {
var files = e.target.files;
var fileName = files[0].name;
for (var i = 0, f; f = files[i]; i++) {
var k = ContactsFS.storeFile(f);
Session.set('fileID', k);
}}
Server side:
ContactsFS.fileHandlers({
default1: function(options) {
return {
blob: options.blob,
fileRecord: options.fileRecord // if no blob then save result in fileHandle (added createdAt)
};
}});
Then I can call the url in html with the given function from collectionFS documentation:
{{cfsFileUrl "default1" fileId=fileId collection="ContactsFS"}}
Once again the problem isn't generating the url. Both locally and once deployed the app displays a url. It is using the image url as the source for the image tag that is giving me the problem.
CollectionFS had a bug. I contacted the creator with the issue and it is now resolved in the collectionFS package. The report and closed issue can be found at:
https://github.com/raix/Meteor-CollectionFS/issues/85

Resources