Issue while uploading image
See original GitHub issueI20200123-18:57:34.751(5.5)? Exception while invoking method 'collections.images.insert' TypeError: Cannot read property 'insert' of undefined
I20200123-18:57:34.753(5.5)? at MethodInvocation.collections.images.insert (imports/api/collections/methods.js:20:31)
I20200123-18:57:34.753(5.5)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1771:12)
I20200123-18:57:34.753(5.5)? at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20200123-18:57:34.754(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200123-18:57:34.754(5.5)? at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20200123-18:57:34.754(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200123-18:57:34.754(5.5)? at Promise (packages/ddp-server/livedata_server.js:715:46)
I20200123-18:57:34.755(5.5)? at new Promise (<anonymous>)
I20200123-18:57:34.755(5.5)? at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20200123-18:57:34.755(5.5)? at packages/ddp-server/livedata_server.js:559:43
Collection constructor server Code :
import { FilesCollection } from 'meteor/ostrio:files';
const Collections_Images = new FilesCollection({
collectionName: 'collections_images',
storagePath: 'uploads/Collections-Images',
allowClientCode: false,
onBeforeUpload(file) {
// Allow upload files under 10MB, and only in png/jpg/jpeg formats
if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.extension)) {
return true;
}
return 'Please upload image, with size equal or less than 10MB';
}
});
export default Collections_Images;
Created method Code :
import { Meteor } from 'meteor/meteor';
import { Collections_Images } from './collections_img.js';
Meteor.methods({
'collections.images.insert'(images) {
return Collections_Images.insert({
file : images,
streams: 'dynamic',
chunkSize: 'dynamic',
})
},
});
Client side js code:
"change #myFileInput" : function(event){
const images = event.currentTarget.files[0];
Meteor.call('collections.images.insert',images, (error) => {
if(error){
alert("collection image insert : "+error.message);
}
else{
images=null;
}
});
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Error Message: There are errors below. Hover over each for ...
We're sorry you're having trouble uploading an image! Sometimes these messages show up when uploading an image from your computer.
Read more >5 Easy Steps to Fix an Http Error When Uploading Images to ...
5 Steps to Fix an HTTP Error When Uploading Images to WordPress · Step 1: Find Out If the HTTP Error is Temporary...
Read more >How to Fix Image Upload Issue in WordPress (Step by Step)
The image upload issue in WordPress is typically caused by incorrect file permissions. Your WordPress files are stored on your web hosting ...
Read more >5 Ways to Fix Common WordPress Image Upload Issues
1. Rename, Resize, and Re-Upload the Image · 2. Increase the Memory Limit · 3. Deactivate Your Plugins · 4. Clear the Cache...
Read more >How to Quickly Fix Image Upload Issues in WordPress
Another sign of this issue is that your images may not appear in the media library. You can then change the file permissions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

But now my problem is solved. As
.insert(update)method is on client side. And Correct importing of Collection_img.js is :import Collections_Images from './collections_img.js';because i’m exporting default from ‘./collections_img.js’Again Thanks @jankapunkt and @dr-dimitru for your help.
@kaushalbrahmbhatt38 I’m glad it’s solved. Feel free to reopen it in case if the issue is still persists on your end.
Please support this project with: