Method: Curl::PostField.file

Defined in:
ext/curb_postfield.c

.Curl::PostField.file(name, local_file_name) ⇒ #<Curl::PostField...> .Curl::PostField.file(name, local_file_name, remote_file_name = local_file_name) ⇒ #<Curl::PostField...> .Curl::PostField.file(name, remote_file_name) {|field| ... } ⇒ #<Curl::PostField...>

Create a new Curl::PostField for a file upload field, supplying the local filename to read from, and optionally the remote filename (defaults to the local name).

The block form allows a block to supply the content for this field, called during the perform. The block should return a ruby string with the field data.

Overloads:



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'ext/curb_postfield.c', line 255

static VALUE ruby_curl_postfield_new_file(int argc, VALUE *argv, VALUE klass) {
  // TODO needs to handle content-type too 
  ruby_curl_postfield *rbcpf = ALLOC(ruby_curl_postfield);
  
  rb_scan_args(argc, argv, "21&", &rbcpf->name, &rbcpf->local_file, &rbcpf->remote_file, &rbcpf->content_proc);
  
  // special handling if theres a block, second arg is actually remote name.
  if (rbcpf->content_proc != Qnil) {
    if (rbcpf->local_file != Qnil) {
      // we were given a local file
      if (rbcpf->remote_file == Qnil) {
        // we weren't given a remote, so local is actually remote
        // (correct block call form)
        rbcpf->remote_file = rbcpf->local_file;
      }
      
      // Shouldn't get a local file, so can ignore it.
      rbcpf->local_file = Qnil;
    }
  } else {
    if (rbcpf->remote_file == Qnil) {
      rbcpf->remote_file = rbcpf->local_file;
    }
  }    
      
  /* assoc objects */
  rbcpf->content = Qnil;
  rbcpf->content_type = Qnil;
  rbcpf->buffer_str = Qnil;
  
  return Data_Wrap_Struct(cCurlPostField, curl_postfield_mark, curl_postfield_free, rbcpf);
}