# Photos file names changed during upload

**URL:** <https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017>\
**Category:** General\
**Created:** [January 29, 2025, 2:28pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017 "2025-01-29T14:28:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpoloni](https://community.epicollect.net/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rpoloni](https://community.epicollect.net/u/rpoloni)\
**Post date:** [January 29, 2025, 2:28pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/1 "2025-01-29T14:28:33Z")

</div>

### Project Name (if applicable, otherwise just type n/a)

N/A

### Question

Hi guys, thank you first of all for this great application for collecting data in the field. I adapted an R script I had previously, which allowed me to process samples collected in the field, to use epicollect.  
I have very simple projects: per each field record I have only three fields: field code (mandatory), place (locality or city) and photo. In the photo there is all I need: the date, the gps coordinates and the photo itself needed to identify the species). This is very convenient because I usually avoid to write down too many things in the field, because you are always in a rush. Then, with the script, I complete the table from epicollect with the rest (coordinates and date) and process the data. However, when I download my data the photo name is changed, so I cannot automatically take it from a folder using the table exported from the epicollect project.  
So, the question is: why the name of the photo is changed compared to the one given by my phone? I can of course download all the pictures from epicollect project, but since there is no bulk download and I have everything already in my google drive, it would be much more convenient if the names were not changed.

---

<div class="post-metadata">

**Author:** ![Epicollect5](https://community.epicollect.net/user_avatar/community.epicollect.net/epicollect5/32/2653_2.png) [@Epicollect5](https://community.epicollect.net/u/Epicollect5)\
**Post date:** [January 29, 2025, 3:52pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/2 "2025-01-29T15:52:59Z")

</div>

Renaming file uploads is an important practice that aligns with standard web security and data management best practices.

1. **Ensuring Uniqueness**

2. **Enhancing Security**

3. **Maintaining Consistency and Organization**

4. **Providing a Reference to the Original Name**

Also, be aware that file renaming happens at the device level, before the upload.  
Files created (or imported) in Epicollect5 use the following name convention

```auto
{entry uuid}_{Unix timestamp in seconds}.{ext}
```

---

<div class="post-metadata">

**Author:** ![rpoloni](https://community.epicollect.net/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rpoloni](https://community.epicollect.net/u/rpoloni)\
**Post date:** [January 29, 2025, 5:03pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/3 "2025-01-29T17:03:49Z")

</div>

Hi, thank you for the answer. I see the interest of changing the file name, but it is still really unconvenient for what I have to do. Entering the photo name is not feasible because it is usually very long. I will think about it. The bulk download of pictures could actually solve the issue pretty straightforward!

---

<div class="post-metadata">

**Author:** ![rpoloni](https://community.epicollect.net/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rpoloni](https://community.epicollect.net/u/rpoloni)\
**Post date:** [January 30, 2025, 10:55am UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/4 "2025-01-30T10:55:18Z")

</div>

Hi, I have tested a few things on my side. Downloading the images one by one is a bit of a problem, because all the images are downloaded with the same name, and the exif are changed so that the date of the photo, gps and everything else is not corresponding any more to the original one. is there a way of solving this issue? I feel is a bit of a pity that the media associated to the data are changed, it can result in a loss of data.  
Maybe using the api is another option, but I don’t think it will solve the problem of the exif.

---

<div class="post-metadata">

**Author:** ![Epicollect5](https://community.epicollect.net/user_avatar/community.epicollect.net/epicollect5/32/2653_2.png) [@Epicollect5](https://community.epicollect.net/u/Epicollect5)\
**Post date:** [January 30, 2025, 11:47am UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/5 "2025-01-30T11:47:12Z")

</div>

The EXIF data are not changed by Epicollect5, just copied over.

To download media files using our API have a read at →

> **[Get Media | Epicollect API Guide](https://developers.epicollect.net/media/get-media)**

---

<div class="post-metadata">

**Author:** ![rpoloni](https://community.epicollect.net/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rpoloni](https://community.epicollect.net/u/rpoloni)\
**Post date:** [January 30, 2025, 12:43pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/6 "2025-01-30T12:43:25Z")

</div>

I tried with the API, I provide the code used below. However, the exif are changed, I don’t know why…

```auto
epicoll <- read.csv(epi_csv, header = TRUE) #csv file of the form

#download using api
for (i in 1:nrow(epicoll)) {
  photo_name <- epicoll$X3_TUBE_PHOTO[i]
  field_code <- epicoll$X1_FIELD_CODE[i]
  reqst <- paste0("https://five.epicollect.net/api/export/media/", proj_slug, "?type=photo&format=entry_original&name=", photo_name)
  res = GET(reqst, add_headers("Authorization" = paste("Bearer", token)), write_disk(path = paste0(picture_directory, field_code, ".jpg", sep=""), overwrite = TRUE))
}

```

---

<div class="post-metadata">

**Author:** ![Epicollect5](https://community.epicollect.net/user_avatar/community.epicollect.net/epicollect5/32/2653_2.png) [@Epicollect5](https://community.epicollect.net/u/Epicollect5)\
**Post date:** [January 30, 2025, 2:44pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/7 "2025-01-30T14:44:45Z")

</div>

Below is the API URL to a public photo uploaded to our EC5 Demo Project:

[Photo](https://five.epicollect.net/api/export/media/ec5-demo-project?type=photo&format=entry_original&name=e0734772-f1d3-4bf8-b605-3a9931af6e90_1738237408.jpg)

When we save this photo locally using Chrome and check it against a tool like [Jimpl](https://jimpl.com), we receive the metadata correctly.

 ![Screenshot 2025-01-30 at 15.25.21](https://discourse-space.fra1.digitaloceanspaces.com/original/2X/4/4271e7cef515435f3930af26906f706227232ccb.jpeg)

Or you can analyse the API URL directly using [exifinfo](https://exifinfo.org/)

> **[ec5-demo-project?type=photo&format=entry\_original&name=e0734772-f1d3-4bf...](https://exifinfo.org/detail/DXka5rF3Cfr3l6mvjO5uvw)**
>
> Online tool to analyze and display the meta-data in images and other media files.

---

<div class="post-metadata">

**Author:** ![Epicollect5](https://community.epicollect.net/user_avatar/community.epicollect.net/epicollect5/32/2653_2.png) [@Epicollect5](https://community.epicollect.net/u/Epicollect5)\
**Post date:** [January 30, 2025, 2:50pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/8 "2025-01-30T14:50:18Z")

</div>

Some AI suggestions

Since the API provides the file with EXIF data when accessed directly via the browser, but the EXIF is missing when downloaded via your R script, the issue is likely caused by how `httr::GET()` processes the request.

### **Possible Causes & Fixes:**

#### **1. Ensure `write_disk()` is Writing Binary Data Correctly**

When using `httr::GET()` with `write_disk()`, the API response should be saved as a binary file. Try explicitly setting `mode = "wb"` (write binary) to ensure correct file handling:

```auto
library(httr)

for (i in 1:nrow(epicoll)) {
  photo_name <- epicoll$X3_TUBE_PHOTO[i]
  field_code <- epicoll$X1_FIELD_CODE[i]
  reqst <- paste0("https://five.epicollect.net/api/export/media/", proj_slug, "?type=photo&format=entry_original&name=", photo_name)
  
  res <- GET(reqst, 
             add_headers("Authorization" = paste("Bearer", token)),  
             write_disk(path = paste0(picture_directory, field_code, ".jpg"), overwrite = TRUE), 
             config = list(encoding = "gzip")) # Ensure proper encoding handling
}

```

✅ **Why?** Some file functions in R default to text mode, which may modify the binary structure.

* * *

#### **2. Verify File Integrity After Download**

Check if the downloaded file is corrupted or altered by comparing checksums:

```auto
system(paste("md5sum", paste0(picture_directory, field_code, ".jpg")))

```

Then compare it to the MD5 of the file downloaded manually via the browser.

✅ **Why?** If the checksums don’t match, something is modifying the file during the API download process.

* * *

#### **3. Try `download.file()` Instead of `httr::GET()`**

If `httr::GET()` is altering the file, use `download.file()` instead:

```auto
for (i in 1:nrow(epicoll)) {
  photo_name <- epicoll$X3_TUBE_PHOTO[i]
  field_code <- epicoll$X1_FIELD_CODE[i]
  reqst <- paste0("https://five.epicollect.net/api/export/media/", proj_slug, "?type=photo&format=entry_original&name=", photo_name)
  
  download.file(reqst, destfile = paste0(picture_directory, field_code, ".jpg"), mode = "wb", quiet = FALSE)
}

```

✅ **Why?** `download.file()` directly fetches the file and ensures binary integrity.

* * *

#### **4. Debug the API Response**

To confirm that the API returns a valid image in your script, inspect the response:

```auto
res <- GET(reqst, add_headers("Authorization" = paste("Bearer", token)))

# Check content type
print(headers(res)Since the API provides the file with EXIF data when accessed directly via the browser, but the EXIF is missing when downloaded via your R script, the issue is likely caused by how `httr::GET()` processes the request.

### **Possible Causes & Fixes:**

#### **1. Ensure `write_disk()` is Writing Binary Data Correctly**

When using `httr::GET()` with `write_disk()`, the API response should be saved as a binary file. Try explicitly setting `mode = "wb"` (write binary) to ensure correct file handling:

```

library(httr)

for (i in 1:nrow(epicoll)) {  
photo\_name ← epicoll$X3\_TUBE\_PHOTO[i]  
field\_code ← epicoll$X1\_FIELD\_CODE[i]  
reqst ← paste0(“[https://five.epicollect.net/api/export/media/](https://five.epicollect.net/api/export/media/)”, proj\_slug, “?type=photo&format=entry\_original&name=”, photo\_name)

res ← GET(reqst,  
add\_headers(“Authorization” = paste(“Bearer”, token)),  
write\_disk(path = paste0(picture\_directory, field\_code, “.jpg”), overwrite = TRUE),  
config = list(encoding = “gzip”)) # Ensure proper encoding handling  
}

```auto

✅ **Why?** Some file functions in R default to text mode, which may modify the binary structure.

---

#### **2. Verify File Integrity After Download**

Check if the downloaded file is corrupted or altered by comparing checksums:

```

system(paste(“md5sum”, paste0(picture\_directory, field\_code, “.jpg”)))

```auto

Then compare it to the MD5 of the file downloaded manually via the browser.

✅ **Why?** If the checksums don’t match, something is modifying the file during the API download process.

---

#### **3. Try `download.file()` Instead of `httr::GET()`**

If `httr::GET()` is altering the file, use `download.file()` instead:

```

for (i in 1:nrow(epicoll)) {  
photo\_name ← epicoll$X3\_TUBE\_PHOTO[i]  
field\_code ← epicoll$X1\_FIELD\_CODE[i]  
reqst ← paste0(“[https://five.epicollect.net/api/export/media/](https://five.epicollect.net/api/export/media/)”, proj\_slug, “?type=photo&format=entry\_original&name=”, photo\_name)

download.file(reqst, destfile = paste0(picture\_directory, field\_code, “.jpg”), mode = “wb”, quiet = FALSE)  
}

```auto

✅ **Why?** `download.file()` directly fetches the file and ensures binary integrity.

---

#### **4. Debug the API Response**

To confirm that the API returns a valid image in your script, inspect the response:

```

content-type`)

# Check response status

print(status\_code(res))

```auto

If the `content-type` is not `"image/jpeg"`, something might be altering the response.

---

### **Summary**

✅ Try **adding `mode = "wb"` in `write_disk()`**
✅ Compare **file checksums before and after downloading**
✅ **Use `download.file()` instead of `httr::GET()`**
✅ **Inspect API response headers**
```

---

<div class="post-metadata">

**Author:** ![rpoloni](https://community.epicollect.net/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rpoloni](https://community.epicollect.net/u/rpoloni)\
**Post date:** [January 30, 2025, 4:51pm UTC](https://community.epicollect.net/t/photos-file-names-changed-during-upload/1017/9 "2025-01-30T16:51:57Z")

</div>

Hi, thank you very much for your help! I understand where the problem is.  
I think that it is not an api problem: if I use my script to download the image you provided, the metadata are preserved. It is a problem of how the file it is uploaded in the app with the phone. Upload with the phone = metadata changed, upload of the same picture first on google drive, then downloaded and uploaded with the computer in the form = metadata kept invariate. I feel it is a problem of how the phone deals with geoprivacy: probably the metadata are changed when uploading to an external app to protect the user. I will see with google developer community how this can be solved.
