如何转换CURLOPT_FILE for Google AppEngine?

Since on Google AppEngine CURL and file writing are not allowed I need help to convert the following CURL request so it can be run on it:

$ch = curl_init("http://example.com/external.php");
$fp = fopen("internal.php", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);

fclose($fp);
header("Location:internal.php");

You would need to write the file to google cloud storage. So something like

$in = "http://example.com/external.php";
$out = "gs://bucket/internal.php";

file_put_contents($out, file_get_contents($in));