title: When you upload multiple files using ActiveStorage, is it possible to determine what was just uploaded?
body: <p>I have a model (let's call it Message) that's using Active Storage with <code>has_many_attached</code> to store multiple uploads through a Javascript routine. I'd like to know the URL of the uploads as soon as these are received and processed by the Update action in my controller. Ideally, the response would be in the form of a JSON string, containing the URL of the file that is just uploaded by the Javascript routine.</p>
  
  <p>Other than having to loop through all the uploads, is there a way to obtain this information as they're uploaded?</p>
  
  <p>I'm not using the DirectUpload javascript suggested in the Active Storage guide, in case you're wondering. The Javascript I'm using sends the files to a custom PATCH action <code>/message/:id/new_upload</code> (where :id is the ID of the Message record), with the BLOB file as its only parameter.</p>
  
  <p>I've tried to use something like this:</p>
  
  <pre><code>  def new_upload
      @message.uploads.attach(params[:uploads])
  
      respond_to do |format|
        format.json  {render json: { location: "The URL would go here"} }
      end
    end
  </code></pre>
  
  <p>But the <code>attach</code> line at the beginning doesn't return anything (obviously), all it is is doing is saving the attachments. Is there anything I can use to figure out what was <em>just</em> uploaded?</p>
  
  <h2>UPDATE</h2>
  
  <p>I've managed to make it "work" by doing something like this:</p>
  
  <pre><code>  def new_upload
      @message.uploads.attach(params[:uploads])
      upload_url = rails_blob_url(@message.uploads.blobs.last)
  
      respond_to do |format|
        format.json  {render json: { location: upload_url} }
      end
    end
  </code></pre>
  
  <p>However, this only works for <em>one</em> attachment (the last). Thankfully I only require to upload one file at a time, but I'd prefer to infer the URL by something other than checking the last upload.</p>