Delete media from drone

I’m trying to find a way to delete media saved on the drone’s SD card from either the SDK or a URL request. I’m using the method listed here for accessing a listing of available media on the drone and determining a URL for downloading the picture: Downloading media from Drone through SkyControlller RNDIS - #2 by Nicolas

I can’t find anything listed in the SDK for interacting with media this way. Is there something available that I have missed or a request similar to the one in the post above (for accessing media) that could be used to delete individual photos or videos?

Hi

You can list available medias using: REST/JSON media API http://192.168.42.1/api/v1/media/medias for a physical drone and http://10.202.0.1/api/v1/media/medias for a simulated drone.

This API endpoint returns a JSON data structure which is a list of media that might look like this:

[
  {
    "media_id": "10000001",
    "type": "PHOTO",
    "datetime": "19700101T000949+0000",
    "size": 4338126,
    "run_id": "D42C35807315EDB8893F0C577975D02E",
    "thumbnail": "/data/thumbnails/100000010001.JPG",
    "resources": [
      {
        "media_id": "10000001",
        "resource_id": "100000010001.JPG",
        "type": "PHOTO",
        "format": "JPG",
        "datetime": "19700101T000949+0000",
        "size": 4338126,
        "url": "/data/media/100000010001.JPG",
        "width": 4608,
        "height": 3456,
        "thumbnail": "/data/thumbnails/100000010001.JPG",
        "md5": ""
      }
    ],
    "photo_mode": "SINGLE" } ]

each media can have multiple resource (when photo_mode=“burst” for example).
To download a media resource, you just have to HTTP GET the resource URL for example:
http://192.168.42.1/data/media/100000010001.JPG
To delete a media resource, just send an HTTP DELETE request to the same resource URL.

The (media) web API documentation should be published by Parrot soon (you are not the only one requesting it).

In the meantime, you can find here a web API usage example using python/requests to download and analyze the metadata of some photo bursts (I hope this might help you getting started).

1 Like

Hi,

I changed the example code from link to download every single image from drone which works. However when I send requests.delete instead of request.get I get an

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://192.168.42.1//data/media/100000540632.JPG

Here is the code which is working fine unless I uncomment the last 2 lines to delete which will throw the above error:

# Example program to download/delete images from drone.
# Media Not Yet Indexed error means usb still connected.
# http://192.168.42.1/data/media/100000040004.JPG

import olympe
import os
import re
import requests
import shutil
import tempfile
import xml.etree.ElementTree as ET


# Drone IP
ANAFI_IP = "192.168.42.1"

# Drone web server URL
ANAFI_URL = "http://{}/".format(ANAFI_IP)
# Drone media web API URL
ANAFI_MEDIA_API_URL = ANAFI_URL + "api/v1/media/medias"

# download the photos associated with this media id
media_info_response = requests.get(ANAFI_MEDIA_API_URL)
print("id : ", ANAFI_MEDIA_API_URL)
media_info_response.raise_for_status() #check for error, should be in try except block?
download_dir = 'images/'


# media_info_response.json() is a list of media_id_dict
# media_id_dict is a dict containing general info about that media_id as well as 'resources' dict which contains info on each image.
# resource is a dict inside of the media 
for media_id_dict in media_info_response.json():
	for resource in media_id_dict["resources"]:
		print("Downloading ", ANAFI_URL + resource["url"])
		image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
		image_response.raise_for_status()
		download_path = os.path.join(download_dir, resource["resource_id"])
		with open(download_path, "wb") as image_file:
            		shutil.copyfileobj(image_response.raw, image_file)

		print("Deleting ", ANAFI_URL + resource["url"])
		######### trying to delete returns HTTPerror: 400 bad request for url. ###############
		#image_response = requests.delete(ANAFI_URL + resource["url"], stream=True)
		#image_response.raise_for_status()

Thanks for the help

Delete a media

DELETE /api/v1/media/medias/<media_id>

Parameters:
media_id : string required
the unique id of the media to delete

Response:

  • Success:
    | 200 | empty |

  • Error:
    | 400 | if the request is incorrect |
    | 404 | if the requested media does not exist |
    | 500 | if there is a server internal error |
    | 524 | if the request has reached timeout (the request may or may not success later, use removed event as a fallback) |
    | 541 | if media are not yet indexed (retry after indexed event) |

Example:

Delete the media with id 12300456

DELETE /api/v1/media/medias/12300456

Delete all media

DELETE /api/v1/media/medias

Response:

  • Success:
    | 200 | empty |

  • Error:
    | 400 | if the request is incorrect |
    | 500 | if there is a server internal error |
    | 524 | if the request has reached timeout (the request may or may not success later, use removed event as a fallback) |
    | 541 | if media are not yet indexed (retry after indexed event) |

Example:

Delete all media

DELETE /api/v1/media/medias
2 Likes

thanks

Hi,

For your information, Olympe 1.2.0 has just been released with a new media API.

Nicolas

1 Like