Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Download files different than .txt  (Read 8241 times)

0 Members and 1 Guest are viewing this topic.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Download files different than .txt
« on: October 21, 2009, 11:11:54 pm »
I would like to download, for example, an image.

I do. Then I get the char* from the string received by the response, and try to make an image loading from memory.

LoadFromMemory returns error. I put the code here.

Code: [Select]
// Create Http
sf::Http Http;
Http.SetHost("www.64digits.com");

// Create request
sf::Http::Request Request;
Request.SetMethod(sf::Http::Request::Get);
Request.SetURI("/users/Panithadrum/preview.gif");

// Send request & Get response
sf::Http::Response Page = Http.SendRequest(Request);

const char *pixels = Page.GetBody().c_str();
sf::Image image;
if (!image.LoadFromMemory(pixels, sizeof(pixels)))
{
std::cout << "error loading from memory" << std::endl;
}


Any idea? Do I have to do something with my char pointer?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Download files different than .txt
« Reply #1 on: October 22, 2009, 08:37:55 am »
sizeof(pixels) will return the size of a pointer, not the number of pixels pointed by pixels. Rather use Page.GetBody().size().

By the way, SFML doesn't support the GIF format.
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Download files different than .txt
« Reply #2 on: October 22, 2009, 01:47:01 pm »
Thanks Laurent, that makes sense.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Download files different than .txt
« Reply #3 on: October 23, 2009, 01:14:48 pm »
I have another question:

I should be able to save a downloaded file using the char array.. no mather SFML doesn't support GIF.
What if I download a RAR file?

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Download files different than .txt
« Reply #4 on: October 24, 2009, 02:50:29 am »
SFML doesn't care of the Content-Type. What you do with your char array is in your hands. It's just data and doesn't get interpreted in any way until you explicitly do so.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Download files different than .txt
« Reply #5 on: October 24, 2009, 07:52:30 pm »
I know, I'm just asking for a way to save my downloaded char array hihi (not SFML related)

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Download files different than .txt
« Reply #6 on: October 25, 2009, 12:41:53 am »
Quote from: "panithadrum"
I know, I'm just asking for a way to save my downloaded char array hihi (not SFML related)
write it in a file ? std::copy(array, array+size, std::"ios iterator") something like that.
SFML / OS X developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Download files different than .txt
« Reply #7 on: October 25, 2009, 04:03:04 pm »
Read about std::ofstream.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Download files different than .txt
« Reply #8 on: October 25, 2009, 04:07:56 pm »
Just what is was looking for. Thanks Hiura & Tank!

Lucky me I'm actually using std::ofstream for logging events and so.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Download files different than .txt
« Reply #9 on: October 25, 2009, 05:03:03 pm »
Just make sure to open the file in binary mode. :)

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Download files different than .txt
« Reply #10 on: October 25, 2009, 07:05:37 pm »
I already did :-) It works fine!

Too bad we can't check any progress of the downloaded file...
it would be awesome! :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Download files different than .txt
« Reply #11 on: October 25, 2009, 07:30:10 pm »
Quote
Too bad we can't check any progress of the downloaded file...
it would be awesome!

Planned for SFML 2.
Laurent Gomila - SFML developer