How can i use RestKit to get stream of data (NSData) - restkit

I have a rest server that receives a json but returns content of a file.
I am looking for a way to get the content of the file as NSData.
How can i do that?

Use RestKit only to create the NSURLRequest that you're going to send, then deal with actually sending it and handling the response data yourself, probably using AFNetworking (which RestKit is currently built on top of so you have direct access to).

Related

Mock in Django a Binary file retrieved from an API

I'm using Django and DRF, and I have a view that retrieves a Binary File (Using BinaryFileRenderer) from an external API. This external API brings the binary data from S3.
I need to mock this call so I could test the logic by isolating the API call, but every time I tried I received some error. For example, I tried creating a MockFile class with content, mime_type, and name fields. And I started to receive the error "AssertionError: renderer returned Unicode, and did not specify a charset value."
After some investigation, apparently, it was expecting some kind of Renderer file. But this is when I got confused. Because Python is dynamic, I'm never sure what kind of file I received and I'm not sure how I can mock the binary file I'm receiving.
Anyone can point me to how correctly mock this binary file?

Any way to handle Stream Json with RestTemplate?

Is there any way to handle application/stream+json content with the old fashioned RestTemplate the way webClient does?
As far as my attempts go, wrapping the results of something like restTemplate.getForEntity in Flux.just(<convert response entity to mono here>) would just return the first element and stop at that, while webClient handles it properly, populating that resulting json with new entries as they appear. Haven't tried working with inputStream yet, but at first glance it doesn't seem to be what i need, despite having a "stream" in its name.
Unfortunately, using webClient would be a rather costly option in this case (still waiting for https://github.com/spring-projects/spring-security/issues/4921). I'd rather implement things that would "soon" appear officially only if there's absolutely no other way.
RestTemplate is exposing an API which is not meant to be used to stream the HTTP response. The underlying HTTP response is read and closed after each call, whereas the "application/stream+json" media type is meant for streaming responses.
I don't see any way to properly handle this use case (reading streaming responses) with RestTemplate, by design (check out SPR-14882 for another example of that). So you'll probably have to wait for that issue to be resolved or use another HTTP client with such features.

(Multipart) zip upload in ruby webmachine handled by rack

I'm making an upload form for zips in a ruby webmachine app. My idea is to have an upload through my backend where I can add some extra params and then upload it to amazons s3 service with RestClient.
I did successfully create a direct upload (web based form post) to a s3bucket, but in that way I'm unable to handle the variables which are needed in the request, the way I want.
I've tried several things but I can't figure out, how to handle the request, as soon as it gets in my backend. I've created a resource and I'm debugging directly in the process_post method.
My #request variable represents a Webmachine::Request, with a Webmachine::Adapters::Rack::RequestBody and a Rack::Request, but I can't get the file out of it to use it as input for my RestClient request.
I think; #request.body.to_s and #request.body.to_io, represent the uploaded file in some way, and I tried to use them as input for Rack::Multipart methods, but that doesn't give me the file.
I also tried to work with the rack-raw-upload gem, but I can't get the mime-type something else than "application/x-www-form-urlencoded" or multipart. I do explicitly set it to; application/octet-stream
Things like File.new(filename, 'rb') gave me `rrno::ENOENT: No such file or directory # rb_sysopen'. For filename I just used 'example.zip'.
I guess I'm missing something which has to do with the Rack::Request call(env) method.
Does somebody have an idea, on how to handle the Rack uploads? Or give me any hints for a new direction? Thanks.
I've created a gist which shows how to retrieve the multipart stream. You'll need further parsing in order to get the uploaded file.
https://gist.github.com/jewilmeer/eb40abd665b70f53e6eb60801de24342

how to use Ajax to get content from JSON files dynamically in DART?

I know how to use JSON in dart also communicating with a server using the HttpRequest API from the dart:html library and parsing JSON data using the dart:convert !!https://www.dartlang.org/articles/json-web-service/
I am looking for Dynamic content loading using Ajax asynchronous methods or calls in DART! ..
like .. the web page need to load content dynamically if there is any change or update in JSON files in server! ..
And how to do this in Angular Dart!?
There's no way to be notified when something changes on the server without either a) polling for changes (this can be pretty wasteful) or b) having the server notify you.
For (a), you could create a periodic timer that fetches the JSON or checks whether it's been updated (you'd need some way of checking this with the server).
A better fit would be something like Web Sockets, with the server able to push your JSON to the client whenever it changes. However, this is quite an architecture change from pulling JSON from the server, because you would need to be holding web sockets open between the server and all clients that have the page loaded, so the server can send the data to them all whenever it changes.
There are some samples of using Web Sockets on the Dart site; but bear in mind you'll need something on the server, this won't work if you only have access to the client.

Ajax file upload in node.js

I want to upload ajax file upload which uses xhr to send file data,
at client m using this
http://valums.com/ajax-upload/
how i will accept this data on node and save the file to server by node.js , which module i need to use in node.js?
I've created an uploader with progress bar using the formidable module, it's really easy to use and provides a lot of useful callbacks.
Have a look here:
https://github.com/felixge/node-formidable (scroll down to get the Docs)
http://debuggable.com/posts/parsing-file-uploads-at-500-mb-s-with-node-js:4c03862e-351c-4faa-bb67-4365cbdd56cb
due to the lack of an example file in valums ajax-uploader, I've just created one.
It catches up the XHR upload if possible, alternatively falling back to the old form-based method.
All in conclusion to valums ajax-uploader.
https://github.com/aldipower/file-uploader/blob/master/server/nodejs.js
Maybe Valums will accept the pull request some time and the sample file gets merged in the standard repository.

Resources