23
23
* @stability: Unstable
24
24
* @include: gdata/gdata-upload-stream.h
26
* #GDataUploadStream is a #GOutputStream subclass to allow uploading of files from GData services with authentication from a #GDataService.
26
* #GDataUploadStream is a #GOutputStream subclass to allow uploading of files from GData services with authorization from a #GDataService under
27
* the given #GDataAuthorizationDomain. If authorization is not required to perform the upload, a #GDataAuthorizationDomain doesn't have to be
28
30
* Once a #GDataUploadStream is instantiated with gdata_upload_stream_new(), the standard #GOutputStream API can be used on the stream to upload
29
31
* the file. Network communication may not actually begin until the first call to g_output_stream_write(), so having a #GDataUploadStream around is no
59
61
* connection will be closed immediately. i.e. #GDataUploadStream will do its best to instruct the server to cancel the upload and any associated
60
62
* server-side changes of state.
62
* If the server returns an error message (for example, if the user is not correctly authenticated or doesn't have suitable permissions to upload
63
* from the given URI), it will be returned as a #GDataServiceError by g_output_stream_close().
64
* If the server returns an error message (for example, if the user is not correctly authenticated/authorized or doesn't have suitable permissions
65
* to upload from the given URI), it will be returned as a #GDataServiceError by g_output_stream_close().
66
68
* <title>Uploading from a File</title>
68
70
* GDataService *service;
71
* GDataAuthorizationDomain *domain;
69
72
* GCancellable *cancellable;
70
73
* GInputStream *input_stream;
71
74
* GOutputStream *upload_stream;
98
101
* /<!-- -->* Create the upload stream *<!-- -->/
99
102
* service = create_my_service ();
103
* domain = get_my_authorization_domain_from_service (service);
100
104
* cancellable = g_cancellable_new (); /<!-- -->* cancel this to cancel the entire upload operation *<!-- -->/
101
* upload_stream = gdata_upload_stream_new (service, SOUP_METHOD_POST, upload_uri, NULL, g_file_info_get_display_name (file_info),
105
* upload_stream = gdata_upload_stream_new (service, domain, SOUP_METHOD_POST, upload_uri, NULL, g_file_info_get_display_name (file_info),
102
106
* g_file_info_get_content_type (file_info), cancellable);
103
107
* g_object_unref (file_info);
109
113
* g_object_unref (upload_stream);
110
114
* g_object_unref (input_stream);
111
115
* g_object_unref (cancellable);
116
* g_object_unref (domain);
112
117
* g_object_unref (service);
245
252
* GDataUploadStream:service:
247
* The service which is used to authenticate the upload, and to which the upload relates.
254
* The service which is used to authorize the upload, and to which the upload relates.
251
258
g_object_class_install_property (gobject_class, PROP_SERVICE,
252
259
g_param_spec_object ("service",
253
"Service", "The service which is used to authenticate the upload.",
260
"Service", "The service which is used to authorize the upload.",
254
261
GDATA_TYPE_SERVICE,
255
262
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
265
* GDataUploadStream:authorization-domain:
267
* The authorization domain for the upload, against which the #GDataService:authorizer for the #GDataDownloadStream:service should be
268
* authorized. This may be %NULL if authorization is not needed for the upload.
272
g_object_class_install_property (gobject_class, PROP_AUTHORIZATION_DOMAIN,
273
g_param_spec_object ("authorization-domain",
274
"Authorization domain", "The authorization domain for the upload.",
275
GDATA_TYPE_AUTHORIZATION_DOMAIN,
276
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
258
279
* GDataUploadStream:method:
260
281
* The HTTP request method to use when uploading the file.
373
394
/* Make sure the headers are set */
374
395
klass = GDATA_SERVICE_GET_CLASS (priv->service);
375
if (klass->append_query_headers != NULL)
376
klass->append_query_headers (priv->service, priv->message);
396
if (klass->append_query_headers != NULL) {
397
klass->append_query_headers (priv->service, priv->authorization_domain, priv->message);
378
400
if (priv->slug != NULL)
379
401
soup_message_headers_append (priv->message->request_headers, "Slug", priv->slug);
416
438
g_object_unref (priv->service);
417
439
priv->service = NULL;
441
if (priv->authorization_domain != NULL)
442
g_object_unref (priv->authorization_domain);
443
priv->authorization_domain = NULL;
419
445
if (priv->message != NULL)
420
446
g_object_unref (priv->message);
421
447
priv->message = NULL;
457
483
case PROP_SERVICE:
458
484
g_value_set_object (value, priv->service);
486
case PROP_AUTHORIZATION_DOMAIN:
487
g_value_set_object (value, priv->authorization_domain);
460
489
case PROP_METHOD:
461
490
g_value_set_string (value, priv->method);
492
521
priv->service = g_value_dup_object (value);
493
522
priv->session = _gdata_service_get_session (priv->service);
524
case PROP_AUTHORIZATION_DOMAIN:
525
priv->authorization_domain = g_value_dup_object (value);
495
527
case PROP_METHOD:
496
528
priv->method = g_value_dup_string (value);
966
998
* gdata_upload_stream_new:
967
999
* @service: a #GDataService
1000
* @domain: (allow-none): the #GDataAuthorizationDomain to authorize the upload, or %NULL
968
1001
* @method: the HTTP method to use
969
1002
* @upload_uri: the URI to upload
970
1003
* @entry: (allow-none): the entry to upload as metadata, or %NULL
998
1031
* Return value: a new #GOutputStream, or %NULL; unref with g_object_unref()
1002
1035
GOutputStream *
1003
gdata_upload_stream_new (GDataService *service, const gchar *method, const gchar *upload_uri, GDataEntry *entry,
1036
gdata_upload_stream_new (GDataService *service, GDataAuthorizationDomain *domain, const gchar *method, const gchar *upload_uri, GDataEntry *entry,
1004
1037
const gchar *slug, const gchar *content_type, GCancellable *cancellable)
1006
1039
g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
1040
g_return_val_if_fail (domain == NULL || GDATA_IS_AUTHORIZATION_DOMAIN (domain), NULL);
1007
1041
g_return_val_if_fail (method != NULL, NULL);
1008
1042
g_return_val_if_fail (upload_uri != NULL, NULL);
1009
1043
g_return_val_if_fail (entry == NULL || GDATA_IS_ENTRY (entry), NULL);
1012
1046
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
1014
1048
/* Create the upload stream */
1015
return G_OUTPUT_STREAM (g_object_new (GDATA_TYPE_UPLOAD_STREAM, "method", method, "upload-uri", upload_uri, "service", service,
1016
"entry", entry, "slug", slug, "content-type", content_type, "cancellable", cancellable, NULL));
1049
return G_OUTPUT_STREAM (g_object_new (GDATA_TYPE_UPLOAD_STREAM,
1051
"upload-uri", upload_uri,
1053
"authorization-domain", domain,
1056
"content-type", content_type,
1057
"cancellable", cancellable,
1073
1115
* gdata_upload_stream_get_service:
1074
1116
* @self: a #GDataUploadStream
1076
* Gets the service used to authenticate the upload, as passed to gdata_upload_stream_new().
1118
* Gets the service used to authorize the upload, as passed to gdata_upload_stream_new().
1078
* Return value: (transfer none): the #GDataService used to authenticate the upload
1120
* Return value: (transfer none): the #GDataService used to authorize the upload
1132
* gdata_upload_stream_get_authorization_domain:
1133
* @self: a #GDataUploadStream
1135
* Gets the authorization domain used to authorize the upload, as passed to gdata_upload_stream_new(). It may be %NULL if authorization is not
1136
* needed for the upload.
1138
* Return value: (transfer none) (allow-none): the #GDataAuthorizationDomain used to authorize the upload, or %NULL
1142
GDataAuthorizationDomain *
1143
gdata_upload_stream_get_authorization_domain (GDataUploadStream *self)
1145
g_return_val_if_fail (GDATA_IS_UPLOAD_STREAM (self), NULL);
1146
return self->priv->authorization_domain;
1090
1150
* gdata_upload_stream_get_method:
1091
1151
* @self: a #GDataUploadStream