#32549 closed defect (bug) (fixed)
wp_remote_get does not stream to temp file
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.3 | Priority: | normal |
Severity: | normal | Version: | 4.1 |
Component: | HTTP API | Keywords: | |
Focuses: | Cc: |
Description
Source:
$filename = wp_unique_filename( get_temp_dir(), basename( $zip_url ) ); var_dump(get_temp_dir()); var_dump($zip_url); var_dump($filename); $response = wp_remote_get( $zip_url, array( 'timeout' => 15, 'stream' => true, 'filename' => $filename ) );
Output:
string(49) "/var/folders/4p/s0vgsy5s19g63q9t0zd56hkw0000gn/T/" string(77) "https://bucket.s3-eu-west-1.amazonaws.com/folder/file.zip" string(8) "file.zip"
Seems like wp_unique_filename
cannot combine filename with temp path. No error returned after download. wp_remote_get
crafts download path the same way so it's broken too if I omit filename option.
Change History (5)
#2
@
10 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
The stream
parameter expects a filename
path to be specified, ie. /var/folders/4p/s0vgsy5s19g63q9t0zd56hkw0000gn/T/file.zip
, not file.zip
. If you pass a relative path into that, it's saved within the current working directory (in my testing, it went into wp-admin/
as I triggered it through wp-admin/admin-post.php
).
wp_unique_filename()
only returns a file name, it does not return a path, it's designed to find a unique filename within a folder.
It looks like you want to be using $filename = wp_tempnam( $zip_url );
instead of wp_unique_filename()
.
#3
@
10 years ago
- Milestone set to 4.3
- Resolution invalid deleted
- Status changed from closed to reopened
Failed to realise exactly what the ticket was referring to - WP_HTTP::request()
does indeed incorrectly use wp_unique_filename()
, and wp_tempnam()
is only defined in an admin context.
$filename = get_temp_dir() . '/' . wp_unique_filename( get_temp_dir(), basename( $zip_url ) ); $response = wp_remote_get( $zip_url, array( 'timeout' => 15, 'stream' => true, 'filename' => $filename ) );
The code in WP_Http::request() does need to be fixed.