1

How to send images/screenshots with ShareX custom uploader

Hi everyone, I've been attempting to connect ShareX custom uploader to send screenshots to Pushover with no avail and could really use the help from someone more experienced than myself. I've looked at example custom uploaders for other services (e.g. these), read and re-read the Pushover documentation but can't seem to get the right mix of settings to get attachments to send with an attachment.

Here is what the best interpretation I could come up with of the Pushover API code, can someone help me get images as attachments to work?

{
  "Version": "15.0.0",
  "Name": "Pushover",
  "DestinationType": "FileUploader",
  "RequestMethod": "POST",
  "RequestURL": "https://api.pushover.net/1/messages.json",
  "Parameters": {
    "token": "XXX",
    "user": "XXX",
    "message": "some message",
    "attachment": null
  },
  "Body": "MultipartFormData",
  "Arguments": {
    "Content-Disposition": "name=\"dadjoke.png\"",
    "Content-Type": "image/png"
  },
  "FileFormName": "file_image"
}
 

fwiw I started with this image as an example for the Content-Disposition, but obviously I want to send screenshots image/png

ShareX Custom uploader guide
Pushover API

 
 
 

1 reply

D

Wasn't able to get it working this way, but thanks to handy dandy chatbots, I was able to get them to write a Python script which runs as an external application after capture in ShareX. To make it "portable" I created an exe file with PyInstaller. Obviously a lot more bulk and footprint than going directly through ShareX, but at least it works.

This takes the input file as a passed argument.

# Replace with your Pushover credentials
pushover_token = "PUSHOVER_TOKEN_HERE"
user_key = "USER_KEY_HERE"

def send_screenshot_to_pushover(screenshot_path):
    """Sends a screenshot to Pushover."""

    url = "https://api.pushover.net/1/messages.json"

    files = {
        "attachment": (os.path.basename(screenshot_path), open(screenshot_path, "rb"), "image/png")
    }

    data = {
        "token": pushover_token,
        "user": user_key,
        "message": "Bard file",  # Optional message to accompany the image
    }

    response = requests.post(url, files=files, data=data)

    if response.status_code == 200:
        print("Screenshot sent successfully!")
    else:
        print("Error sending screenshot:", response.text)

# Access screenshot path from command-line argument
if __name__ == "__main__":
    if len(sys.argv) > 1:  # Check if a screenshot path is provided
        screenshot_path = sys.argv[1]
        send_screenshot_to_pushover(screenshot_path)
    else:
        print("Please provide a screenshot path as an argument.")

Create a new task:

Task Settings -> Actions -> Add

D

Add

```

import sys
import os
import requests

```

to the beginning