How do I create an image object from a remote image url

How do I create an image object from a remote image url in rails console

How do I create an image object from a remote image url in rails console

What do you mean by image object?

Colin

An object returned by Nokogiri as a result of selecting a css.(“a”) element containing

That doesn’t make sense, you ask how to create an image object, then say that an image object is an object returned by nokogiri. So to create it all you have to do is make that request to nokogiri.

Colin

https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location

Using ActiveStorage but I’ll look at the page thanks

I’m trying to insert an image into the assets table from web scraping Scraping gets me the src of the image I don’t know if I should submit a form or do a raw insert in my script

How do I create an image object from a remote image url in rails console

What do you mean by image object?

An object returned by Nokogiri as a result of selecting a css.("a") element containing <img src="...">

That doesn't make sense, you ask how to create an image object, then say that an image object is an object returned by nokogiri. So to create it all you have to do is make that request to nokogiri.

Colin

I'm trying to insert an image into the assets table from web scraping Scraping gets me the src of the image I don't know if I should submit a form or do a raw insert in my script

Read the documentation for your file upload package -- I believe you mentioned ActiveStorage -- about uploading from a URL. This is a common feature in many file attachment systems. CarrierWave, Shrine, CarrierWave, even Paperclip have a way to do this.

It usually amounts to something like

require 'open-uri'
file = open(remote_url).read
@your_instance.file = file
@your_instance.save # (the file should be persisted locally)

Walter

Thanks, I’ll use Carrierwave because when I googled “ActiveStorage remote file upload” what I found was a discussion where someone says you can’t do this in ActiveStorage but you can with Carrierwave

>
>
>
>
>
> How do I create an image object from a remote image url in rails console
>
> What do you mean by image object?
>
>
> An object returned by Nokogiri as a result of selecting a css.("a") element containing <img src="...">
>
> That doesn't make sense, you ask how to create an image object, then say that an image object is an object returned by nokogiri. So to create it all you have to do is make that request to nokogiri.
>
> Colin
>
>
> I'm trying to insert an image into the assets table from web scraping Scraping gets me the src of the image I don't know if I should submit a form or do a raw insert in my script

Read the documentation for your file upload package -- I believe you mentioned ActiveStorage -- about uploading from a URL. This is a common feature in many file attachment systems. CarrierWave, Shrine, CarrierWave, even Paperclip have a way to do this.

It usually amounts to something like

require 'open-uri'
file = open(remote_url).read
@your_instance.file = file
@your_instance.save # (the file should be persisted locally)

Walter

>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9f8ba9af-0ad0-4fd0-856b-0f236c76149b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Thanks, I'll use Carrierwave because when I googled "ActiveStorage remote file upload" what I found was a discussion where someone says you can't do this in ActiveStorage but you can with Carrierwave

I'd recommend Shrine. Much better documentation, current development, and a super-responsive development team.

Walter

With ‘require open-uri’ i can just use ActiveStorage don’t need to use a gem?

>
>
>
>
> >
> >
> >
> >
> >
> > How do I create an image object from a remote image url in rails console
> >
> > What do you mean by image object?
> >
> >
> > An object returned by Nokogiri as a result of selecting a css.("a") element containing <img src="...">
> >
> > That doesn't make sense, you ask how to create an image object, then say that an image object is an object returned by nokogiri. So to create it all you have to do is make that request to nokogiri.
> >
> > Colin
> >
> >
> > I'm trying to insert an image into the assets table from web scraping Scraping gets me the src of the image I don't know if I should submit a form or do a raw insert in my script
>
> Read the documentation for your file upload package -- I believe you mentioned ActiveStorage -- about uploading from a URL. This is a common feature in many file attachment systems. CarrierWave, Shrine, CarrierWave, even Paperclip have a way to do this.
>
> It usually amounts to something like
>
> require 'open-uri'
> file = open(remote_url).read
> @your_instance.file = file
> @your_instance.save # (the file should be persisted locally)
>
> Walter
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9f8ba9af-0ad0-4fd0-856b-0f236c76149b%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> Thanks, I'll use Carrierwave because when I googled "ActiveStorage remote file upload" what I found was a discussion where someone says you can't do this in ActiveStorage but you can with Carrierwave
>
>

I'd recommend Shrine. Much better documentation, current development, and a super-responsive development team.

Walter

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2eebec62-614c-4d0e-9834-7c3a80bb4112%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

With 'require open-uri' i can just use ActiveStorage don't need to use a gem?

Open-URI is part of the Ruby standard library, not a third-party Gem. If you are in a Rails app, you won't need to do this, because it's part of the requirements. But if you are building a stand-alone script for testing, as you should, you may need to do this before the Kernel.open command will open a URI.

Walter

Doing everything in rails console so I can let the models do their job