These are chat archives for opal/opal

11th
Nov 2015
Forrest Chang
@fkchang
Nov 11 2015 06:21
@/all I added react support to opal playground http://git.io/v8Sm7
will tabify it also
Martin Becker
@Thermatix
Nov 11 2015 13:23
@all how do I do chunked file-uploads in opal?
Elia Schito
@elia
Nov 11 2015 13:24
@Thermatix are you using opal-browser or opal-jquery?
Martin Becker
@Thermatix
Nov 11 2015 13:24
browser
also
is it possible for the backend (sinatra) to give a progress update every time it gets a chunk?
Elia Schito
@elia
Nov 11 2015 13:25
@Thermatix never tried, google says something?
Martin Becker
@Thermatix
Nov 11 2015 13:25
well, that part isn't important
it's the file upload that is
I was thinking of using the following code for moving the chunked data to a target location https://gist.github.com/sasimpson/1112739
Elia Schito
@elia
Nov 11 2015 13:27
I'd rather search for a javscript in-browser example and then convert it to opal cc @meh
Martin Becker
@Thermatix
Nov 11 2015 13:28
hmm I seee
Mitch VanDuyn
@catmando
Nov 11 2015 14:25
@thermatix - indeed.. there are good jquery plugins for this... no need to write new, although a opal wrapper would be nice!
Mitch VanDuyn
@catmando
Nov 11 2015 14:34
@thermatix, and yes the backend can monitor the progress. I can give you detailed code example for a sinatra app that does this. It does require some apache plugins etc to work (at least pre html5)
Martin Becker
@Thermatix
Nov 11 2015 14:38
I'm currently doing something like this: https://gist.github.com/Thermatix/3a8138baf705b55a565c
for the backend
because I intend to push the uploaded file to a remote server (s3 most probably)
it probably won't be exactly like this
but I'm trying to make it remote server agnostic
also @catmando cool, I Iook forward to seeing it
Mitch VanDuyn
@catmando
Nov 11 2015 14:41
okay... sure I can paste the code someplace, but there are some important things to understand.
you will get MUCH BETTER performance if you client app pushes directly to the cloud service, and then once its there, you can pull onto the server and process. Why? because the cloud storage is highly optimized to receive your files rapidly, at low overhead. But if you send to your server you are tying up a server process for the whole upload story. So for best results it goes like this:
1) client initiates an upload
2) server provides a unique id (or you can just do a random hash on the client)
3) client pushes the files directly to a cloud location named using the id.
4) the cloud service will provide the incremental feedback
5) once done the client notifies the server that there is new data waiting to process
Mitch VanDuyn
@catmando
Nov 11 2015 14:47
Lots of stuff out in google land explaining how to do this. Strongly suggest you do not try to re-invent this particular wheel, as it gets really tricky.
Martin Becker
@Thermatix
Nov 11 2015 15:47
is it possible to remote_require a js file?
Elia Schito
@elia
Nov 11 2015 15:55
@Thermatix yes, but you have to implement it yourself, there's a remote_require in opal-parser, but it's a sync request and fetches ruby code instead of js so it's probably not what you need
Martin Becker
@Thermatix
Nov 11 2015 15:57
hmmm
Martin Becker
@Thermatix
Nov 11 2015 16:04
Ok, so I found a solution here: https://gitter.im/opal/opal
what I'm doing is:
        def load_library &block
          raise 'no provider_url present' unless @provider_url
          %x'
              url = #{@provider_url}
              var script = document.createElement("script")
              script.type = "text/javascript";

              if (script.readyState){  //IE
                  script.onreadystatechange = function(){
                      if (script.readyState == "loaded" ||
                              script.readyState == "complete"){
                          script.onreadystatechange = null;
                          #{block.call}
                      }
                  };
              } else {  //Others
                  script.onload = function(){
                      #{block.call}
                  };
              }

              script.src = url;
              document.getElementsByTagName("head")[0].appendChild(script);
          '
        end
Martin Becker
@Thermatix
Nov 11 2015 17:38
how do I convert #<Native:[object HTMLInputElement]> into a type that a standard file uploader can understand?
with file.name, file.type, etc
meh.
@meh
Nov 11 2015 17:39
Thermatix, call #to_n
Martin Becker
@Thermatix
Nov 11 2015 17:39
ah, thanks!
Martin Becker
@Thermatix
Nov 11 2015 17:52
I can't find the file reader in opal-browser
can some one link it?
meh.
@meh
Nov 11 2015 17:57
Thermatix, it's not implemented if I recall correctly
shouldn't be hard to add tho