diff options
author | Ross Burton <ross@linux.intel.com> | 2010-08-11 10:23:57 +0100 |
---|---|---|
committer | Ross Burton <ross@linux.intel.com> | 2010-08-11 10:23:57 +0100 |
commit | 30bd53e4fb2d1f61fa54a66e2f5dfdce39b8a67b (patch) | |
tree | b2f19b9512028ae295a6becb9d3ffd26d1db7a90 | |
parent | 739027e7e0176ce7c37f422e719c734793e5774b (diff) | |
download | librest-30bd53e4fb2d1f61fa54a66e2f5dfdce39b8a67b.tar.gz |
flickr: get the content type a quicker and better way
-rw-r--r-- | rest-extras/flickr-proxy.c | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/rest-extras/flickr-proxy.c b/rest-extras/flickr-proxy.c index caa159a..2cae090 100644 --- a/rest-extras/flickr-proxy.c +++ b/rest-extras/flickr-proxy.c @@ -407,11 +407,8 @@ RestProxyCall * flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GError **error) { GMappedFile *map; - GFile *file = NULL; - GFileInfo *fi = NULL; GError *err = NULL; - const char *content_type; - char *basename = NULL; + char *basename = NULL, *content_type = NULL; RestParam *param; RestProxyCall *call = NULL; @@ -426,26 +423,14 @@ flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GErr } /* Get the file information */ - file = g_file_new_for_path (filename); - basename = g_file_get_basename (file); - - fi = g_file_query_info (file, - G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, - G_FILE_QUERY_INFO_NONE, - NULL, - &err); - - if (fi == NULL) { - g_propagate_error (error, err); - goto done; - } - - content_type = g_file_info_get_attribute_string (fi, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); + basename = g_path_get_basename (filename); + content_type = g_content_type_guess (filename, + (const guchar*) g_mapped_file_get_contents (map), + g_mapped_file_get_length (map), + NULL); /* Make the call */ call = flickr_proxy_new_upload (proxy); - - /* Now construct the param */ param = rest_param_new_with_owner ("photo", g_mapped_file_get_contents (map), g_mapped_file_get_length (map), @@ -455,10 +440,8 @@ flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GErr (GDestroyNotify)g_mapped_file_unref); rest_proxy_call_add_param_full (call, param); - done: g_free (basename); - g_object_unref (file); - g_object_unref (fi); + g_free (content_type); return call; } |