       %{x: x, y: y, z: z} = Farmbot.BotState.get_current_pos()
       meta = %{x: x, y: y, z: z, name: Path.rootname(path)}
       pid = spawn __MODULE__, :upload, [path, meta]
+      Process.monitor(pid)
       {:noreply, %{state | uploads: Map.put(state.uploads, pid, {path, meta, 0})}}
     else
       # Logger.warn 3, "Not uploading: match: #{matches?} already_uploading?: #{already_uploading?}"

    end
  end

  def handle_info({:EXIT, pid, reason}, state) do
    case state.uploads[pid] do
      nil                   -> {:noreply, state}
      {path, _meta, 6 = ret} ->
        Logger.error 1, "Failed to upload #{path} #{ret} times. Giving up."
        File.rm path
        {:noreply, %{state | uploads: Map.delete(state.uploads, pid)}}
      {path, meta, retries}  ->
        Logger.warn 2, "Failed to upload #{path} #{inspect reason}. Going to retry."
        Process.sleep(1000 * retries)
        new_pid = spawn __MODULE__, :upload, [path, meta]
        new_uploads = state
          |> Map.delete(pid)
          |> Map.put(new_pid, {path, meta, retries + 1})
        {:noreply, %{state | uploads: new_uploads}}
    end
  end

  def handle_info(_, state), do: {:noreply, state}

  # Stolen from
  # https://github.com/phoenixframework/

    end
  end

  def upload(file_path, meta) do
    Logger.busy 3, "Image Watcher trying to upload #{file_path}"
    case Farmbot.HTTP.upload_file(file_path, meta) do
      {:ok, %{status_code: 200}} -> exit(:normal)
      {:ok, %{body: body}} -> exit({:http_error, body})
      {:error, reason} -> exit(reason)
    end
  end
end
