'$this' is causing a problem when uploading a file via file_save_data(),

I modified the function for my own use to ->

public static function getMimeType($uri, $mapping = NULL) {
Drupal_set_message(__FUNCTION__);
Drupal_set_message(func_get_args());

$use_uri = isset($this)?$this->uri:$uri; //I added this line;

$storage = _storage_core_bridge_load($use_uri); //Changed $this->uri to $use_uri;
return $storage->mimetype;
}

Comments

modimanz’s picture

Title: DrupalStorageStreamWrapper static function getMimeType Abscract function call to this error... » DrupalStorageStreamWrapper static function getMimeType Abscract function call to $this error
modimanz’s picture

This is probably a better solution, but there is still a potential problem.

public static function getMimeType($uri, $mapping = NULL) {
Drupal_set_message(__FUNCTION__);
Drupal_set_message(func_get_args());

if (isset($uri)) {
$use_uri = $uri;
if (isset($this)) { //Set $this-uri, Ignore in Abstract function;
$this->uri = $uri;
}
} else $use_uri = isset($this)?$this->uri:NULL;

$storage = _storage_core_bridge_load($use_uri);
return $storage->mimetype;
}

jcarlson34’s picture

I'm wondering if this issue is related to this core issue: http://drupal.org/node/987846

modimanz’s picture

I don't think so. It is retrieving the MIME type, and since it is being called as static function at times we can not use $this while it is a static function. Only when called from an instance of the class object. Therefore we need to tell it to use the $uri argument if there is no $this, however, if $this->uri and $uri is null it will still error out. So that part of the code will need to be addressed. I am guessing a return value of FALSE when both "uri" values are null, but before the call to storage_core_bridge_load() with a NULL argument. Then we need to validate that the calls to ::getMimeType() will be able to handle the false return value.

-modimanz

jcarlson34’s picture

@modimanz ah thanks for the explaination. To the non-coder, it looked very similar. Didn't mean to clog up the queue!

trevorwh’s picture

FYI - I was getting this same issue. The patch/code snippet above fixed this for me and allowed me to display the AWS image.

jbrown’s picture

Is this still a problem?

perignon’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

I am a new co-maintainer for Storage_API. Drupal 6 is coming toward end of life as soon as D8 is released which should be by the end of 2014. Due to that, I am going to be closing all 6.x issues as it's a hurdle too far to overcome with the amount of issues in the queue against this module.