# I have a column of Mid, and I want to extract the File:URL…

**URL:** https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533
**Category:** Support and Helpdesk
**Tags:** wikimedia-commons
**Created:** [May 17, 2024, 6:26pm UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533 "2024-05-17T18:26:27Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)
#### Post date: [May 17, 2024, 6:26pm UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/1 "2024-05-17T18:26:27Z")

</div>

I have a column with a lot of Mid (ex. [M141414969](https://commons.wikimedia.org/entity/M141414969)).  
How can I get the File URL (i.e.: [https://commons.wikimedia.org/wiki/File:MdM\_Micheline\_Legendre\_en\_1975.jpg](https://commons.wikimedia.org/wiki/File:MdM_Micheline_Legendre_en_1975.jpg)) of that image?

Regards, Antoine

![image](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/2X/f/f5c73826955b70e96ba69b307d5cb8b48c3be3f5.png)

---

<div class="post-metadata">

### Author: ![Gnoeee](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/gnoeee/32/429_2.png) [@Gnoeee](https://forum.openrefine.org/u/Gnoeee)
#### Post date: [May 18, 2024, 5:58am UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/2 "2024-05-18T05:58:07Z")

</div>

Right now I'm not sure if there is a direct way in OR similar to getting captions, labels, descriptions and properties from Wikibase. But one way can be fetching the URL (ex: [https://commons.wikimedia.org/entity/M141414969](https://commons.wikimedia.org/entity/M141414969)) and we will get the data which includes the title of the file. So we can construct the File URL from that.

---

<div class="post-metadata">

### Author: ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)
#### Post date: [May 21, 2024, 3:18am UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/3 "2024-05-21T03:18:20Z")

</div>

I will get a redirect (HTTP 301 or 302), but not sure how I can extract that in OR…

Regards, Antoine

---

<div class="post-metadata">

### Author: ![ostephens](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/ostephens/32/8_2.png) [@ostephens](https://forum.openrefine.org/u/ostephens)
#### Post date: [May 21, 2024, 6:36pm UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/4 "2024-05-21T18:36:26Z")

</div>

I think if you set the HTTP "Accept' Header to be `application/json` I think it will return the JSON rather than redirect:

 ![Screenshot 2024-05-21 at 19.35.42](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/2X/3/3f39a8f664a988391406c59d88542a7b40880818.png)

 ![Screenshot 2024-05-21 at 19.35.52](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/2X/1/13e1136c5e606a84e24cb0318f99781ff7b41675.png)

Then maybe something like  
`value.parseJson().entities.get(cells["Img_WCID"].value).title`  
to extract the file name?

---

<div class="post-metadata">

### Author: ![tfmorris](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/tfmorris/32/17_2.png) [@tfmorris](https://forum.openrefine.org/u/tfmorris)
#### Post date: [May 21, 2024, 8:59pm UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/5 "2024-05-21T20:59:05Z")

</div>

Instead of using content negotiation headers, you can also just modify the URL:

[https://commons.wikimedia.org/wiki/Special:EntityData/M141414969.json](https://commons.wikimedia.org/wiki/Special:EntityData/M141414969.json)

although "title" seems like a very odd place to store the file name and I'm not sure how reliable it is.

Perhaps a better approach would be to look at the RDF/XML or Turtle

[https://commons.wikimedia.org/wiki/Special:EntityData/M141414969.ttl](https://commons.wikimedia.org/wiki/Special:EntityData/M141414969.ttl)

[https://commons.wikimedia.org/wiki/Special:EntityData/M141414969.rdf](https://commons.wikimedia.org/wiki/Special:EntityData/M141414969.rdf)

which has (in Turtle) all the attributes of the image object:

sdc:M141414969 a schema:MediaObject,  
schema:ImageObject ;  
schema:encodingFormat "image/jpeg" ;  
schema:contentUrl \<[https://upload.wikimedia.org/wikipedia/commons/2/2c/MdM\_Micheline\_Legendre\_en\_1975.jpg](https://upload.wikimedia.org/wikipedia/commons/2/2c/MdM_Micheline_Legendre_en_1975.jpg)\> ;  
schema:url \<[http://commons.wikimedia.org/wiki/Special:FilePath/MdM%20Micheline%20Legendre%20en%201975.jpg](http://commons.wikimedia.org/wiki/Special:FilePath/MdM%20Micheline%20Legendre%20en%201975.jpg)\> ;  
schema:contentSize "18217"^^xsd:integer ;  
schema:height "140"^^xsd:integer ;  
schema:width "234"^^xsd:integer .

---

<div class="post-metadata">

### Author: ![Andre\_Costa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/andre_costa/32/898_2.png) [@Andre\_Costa](https://forum.openrefine.org/u/Andre_Costa)
#### Post date: [May 22, 2024, 2:11pm UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/6 "2024-05-22T14:11:34Z")

</div>

"title" in the EntityData should be fairly reliable for getting the image page associated with an Mid.

Since the Mid is generated from the pageId you could also just shave of the `M` and query [https://commons.wikimedia.org/w/api.php?action=query&format=json&pageids=141414969](https://commons.wikimedia.org/w/api.php?action=query&format=json&pageids=141414969) to get title value that way.

---

<div class="post-metadata">

### Author: ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)
#### Post date: [May 23, 2024, 4:33am UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/7 "2024-05-23T04:33:40Z")

</div>

@Andre_Costa: This seems fast. Do you know if I can query many on the same call?

This: [https://commons.wikimedia.org/w/api.php?action=query&format=json&pageids=141414969,141414970,141414968](https://commons.wikimedia.org/w/api.php?action=query&format=json&pageids=141414969,141414970,141414968)

Is not working.

Regards, Antoine

---

<div class="post-metadata">

### Author: ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)
#### Post date: [May 23, 2024, 4:34am UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/8 "2024-05-23T04:34:31Z")

</div>

@Gnoeee: I dismissed your answer too fast. It was working, but it’s slow. Thanks.

Regards, Antoine

---

<div class="post-metadata">

### Author: ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)
#### Post date: [May 23, 2024, 4:38am UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/9 "2024-05-23T04:38:18Z")

</div>

@tfmorris: the Json seems easier to parse. It’s just slow.  
Thanks for the alternative solutions.

Regards, Antoine

---

<div class="post-metadata">

### Author: ![Andre\_Costa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/andre_costa/32/898_2.png) [@Andre\_Costa](https://forum.openrefine.org/u/Andre_Costa)
#### Post date: [May 23, 2024, 10:48am UTC](https://forum.openrefine.org/t/i-have-a-column-of-mid-and-i-want-to-extract-the-file-url/1533/10 "2024-05-23T10:48:47Z")

</div>

The separation is done using either the pipe-character

e.g. [https://commons.wikimedia.org/w/api.php?action=query&format=json&pageids=141414969|141414970|141414968](https://commons.wikimedia.org/w/api.php?action=query&format=json&pageids=141414969%7C141414970%7C141414968)

You are allowed max 50 at a go (unless you are logged in with special permissions)
