Downloaded pictures with download.file - function are fragmented

Hello,

as stated in the title all the pictures i download with the download.file - function are heavily fragmented.

For reference the code i am using:

am <- read.xlsx(file.choose())

am$id <- str_extract(am$id, "\\d+")
am <- am[!is.na(am$id), ]
# am[apply(am, 1, function(x) sum(is.na(x)))>=9, ]

library("foreach")
foreach(i = 1:nrow(am)) %do% {
  print(i)
  urls <- str_split(am$image_url[i], "/")
  download.file(am$image_url[i], 
                destfile = paste0(path3,quiet=T,  str_extract_all(urls, "\\d+")[[1]][1], ".jpg"))
}

Even if I only use the download.file-function for one picture it comes out fragmented.

And here how the picture look like vs how they should: (Imgur Link)

Doe anyone know the solution to my problem?

Thanks in advance and i'm more than happy to provide further information if needed

Interesting, I didn't know about that: you apparently need to specify that you want to save the file as binary (on Windows), by setting the mode:

download.file("https://i.imgur.com/1SOXhVA.jpg", "test.jpg", mode="wb")
1 Like

it worked, thank you very much :smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.