Giter VIP home page Giter VIP logo

Comments (6)

davidyell avatar davidyell commented on May 26, 2024

Thanks for submitting a ticket. I had not considered this use-case before, having not used much JS as a front-end. It is focused, as you rightly say, on being posted from PHP.

I would think that updating the request data before it is marshalled would be a good solution.

from cakephp-proffer.

spacebiscuit avatar spacebiscuit commented on May 26, 2024

I'll give it a go - thanks for tip on where to start. I'll post my findings.

from cakephp-proffer.

spacebiscuit avatar spacebiscuit commented on May 26, 2024

I'm not sure how I can set the tmp_name manually with a valid value because although I can easily set an arbitrary value how can I know the random name used for each image temporarily stored, for example these are town examples:

'tmp_name' => 'C:\wamp64\tmp\php6B85.tmp',
'tmp_name' => 'C:\wamp64\tmp\php7318.tmp',

If this is set by PHP how can it be set manually in my Cake app?

Note added: seems I may need access to $_FILES but within my cake app this is empty.

from cakephp-proffer.

davidyell avatar davidyell commented on May 26, 2024

Hmm, perhaps it's worth looking at https://github.com/FriendsOfCake/cakephp-upload and using a custom Writer class and a custom transformer to generate thumbnails using a library of your choice.

I've not used Angular, so I've no idea how it uploads files.

from cakephp-proffer.

spacebiscuit avatar spacebiscuit commented on May 26, 2024

So actually this is a lot simpler than I imagined and all the work which is required is on the front-end side.

What I had to do was use a FormData object to set the file data which then resulted in the file attributes are passed before make the call to the Cake backend:

var dataObj = new FormData();

angular.forEach($scope.listing.listing_images, function(value, key) {
     dataObj.append('listing_images[' + key + ']', value); 
});

$http({
     method: 'post',
     url: frontbaseurl + '/api/listings.json',
     data: dataObj,
     headers: {'Content-Type': undefined},
});

This wasn't obvious to me because to date when posting to the back-end I have simply been passing an object with attributes for each field to be saved. The idea of using a formData object is new but seems to be the solution.

Feel free to close this 'issue'. Thanks!

from cakephp-proffer.

davidyell avatar davidyell commented on May 26, 2024

Glad you figured it out @spacebiscuit, good thought to use a formData object 👍

from cakephp-proffer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.