ccorcos/meteor-clientside-image-manipulation

request: integration w/ yogiben:autoform-file

Closed this issue · 4 comments

hi,

thanks for the package

I tried to merge the two package without luck, I'm just kicking off w/ Meteor

Template.afFileUpload.events
    "change .file-upload": (e, t) ->
    file = e.target.files[0]
    if not file? then return

    imgData = processImage file, 500, 500, (imgData) ->
      newImg = new FS.File(imgData)

      collection = getCollection(t.data)
      collection.insert newImg, (err, fileObj) ->
        if err
          console.log err
        else
          name = $(e.target).attr('file-input')
          # console.log $(e.target)
          # console.log fileObj
          $('input[name="' + name + '"]').val(fileObj._id)
          Session.set 'fileUploadSelected[' + name + ']', file.name
          # console.log fileObj
          refreshFileInput name

do you think you could do a sample on how to do this?

thanks a lot

tinto

Here's a real life example -- not using auto form, but I think it should help...

What I've done here is created a reactive variable to store the image and display the image before uploading it:
https://github.com/ccorcos/taxes/blob/master/client/views/newRecord/newRecord.coffee#L5
https://github.com/ccorcos/taxes/blob/master/client/views/newRecord/newRecord.coffee#L35

Then when it comes time to submit the form, I upload the image just as you would with collectionFS:
https://github.com/ccorcos/taxes/blob/master/lib/collections.coffee#L3
https://github.com/ccorcos/taxes/blob/master/client/views/newRecord/newRecord.coffee#L61
https://github.com/ccorcos/taxes/blob/master/client/views/newRecord/newRecord.coffee#L70

As you can see form the collectionfs documentation, it can accept a data URI string
https://github.com/CollectionFS/Meteor-CollectionFS/blob/devel/README.md#getting-started

And so can an img src:
https://github.com/ccorcos/taxes/blob/master/client/views/newRecord/newRecord.html#L33

That might be overkill, but I hope you get the idea...

thanks, I'll look at these and get back to you

I managed to make the integration, your package was working fine

there was a problem with the autoform-file.coffee file, which after editing didn't compile and threw crazy errors, so at the end I had to convert it to JS

thanks for your support

sweet :)