@@ -196,22 +196,34 @@ public async Task<CreateFeedDocumentResult> CreateFeedDocumentAsync(ContentType
196
196
return null ;
197
197
}
198
198
199
- public string SubmitFeed ( string XmlContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML ) =>
200
- Task . Run ( ( ) => SubmitFeedAsync ( XmlContentOrFilePath , feedType , marketPlaceIds , feedOptions , contentType ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
199
+ public string SubmitFeedFile ( string FilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML ) =>
200
+ Task . Run ( ( ) => SubmitFeedAsync ( FilePath , feedType , marketPlaceIds , feedOptions , contentType , ContentFormate . File ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
201
+
202
+ public async Task < string > SubmitFeedFileAsync ( string FilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML ) =>
203
+ await SubmitFeedAsync ( FilePath , feedType , marketPlaceIds , feedOptions , contentType , ContentFormate . File ) ;
204
+
205
+ public string SubmitFeedContent ( string Content , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML ) =>
206
+ Task . Run ( ( ) => SubmitFeedAsync ( Content , feedType , marketPlaceIds , feedOptions , contentType , ContentFormate . Text ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
207
+
208
+ public async Task < string > SubmitFeedContentAsync ( string Content , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML ) =>
209
+ await SubmitFeedAsync ( Content , feedType , marketPlaceIds , feedOptions , contentType , ContentFormate . Text ) ;
210
+
211
+ public string SubmitFeed ( string XmlContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML , ContentFormate contentFormate = ContentFormate . AutoDetect ) =>
212
+ Task . Run ( ( ) => SubmitFeedAsync ( XmlContentOrFilePath , feedType , marketPlaceIds , feedOptions , contentType , contentFormate ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
201
213
202
214
/// <summary>
203
215
/// read full step https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide_2021-06-30.md
204
216
/// </summary>
205
217
/// <param name="xml"></param>
206
218
/// <param name="feedType"></param>
207
219
/// <returns></returns>
208
- public async Task < string > SubmitFeedAsync ( string feedContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML )
220
+ public async Task < string > SubmitFeedAsync ( string feedContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML , ContentFormate contentFormate = ContentFormate . AutoDetect )
209
221
{
210
222
//We are creating Feed Document
211
223
var feedCreate = CreateFeedDocument ( contentType ) ;
212
224
213
225
//Uploading encoded invoice file
214
- _ = await PostFileDataAsync ( feedCreate . Url , feedContentOrFilePath , contentType ) ;
226
+ _ = await PostFileDataAsync ( feedCreate . Url , feedContentOrFilePath , contentType , contentFormate ) ;
215
227
216
228
CreateFeedSpecification createFeedSpecification = new CreateFeedSpecification ( )
217
229
{
@@ -238,51 +250,63 @@ private static async Task<Stream> GetStreamFromUrlAsync(string url)
238
250
return new MemoryStream ( imageData ) ;
239
251
}
240
252
241
- private async Task < string > PostFileDataAsync ( string destinationUrl , string contentOrFilePath , ContentType contentType = ContentType . XML )
253
+ private async Task < string > PostFileDataAsync ( string destinationUrl , string contentOrFilePath , ContentType contentType = ContentType . XML , ContentFormate contentFormate = ContentFormate . AutoDetect )
242
254
{
243
255
HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( destinationUrl ) ;
244
256
245
- byte [ ] bytes ;
246
- if ( System . IO . Path . IsPathRooted ( contentOrFilePath ) )
257
+ byte [ ] bytes = null ;
258
+ if ( contentFormate == ContentFormate . File )
247
259
{
248
- // The string looks like a file path, so try to read the file
249
- if ( System . IO . File . Exists ( contentOrFilePath ) )
250
- {
251
- bytes = System . IO . File . ReadAllBytes ( contentOrFilePath ) ;
252
- }
253
- else
254
- {
255
- // The file does not exist, so treat the string as content
256
- bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
257
- }
260
+ bytes = System . IO . File . ReadAllBytes ( contentOrFilePath ) ;
261
+ }
262
+ else if ( contentFormate == ContentFormate . Text )
263
+ {
264
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
258
265
}
259
- else if ( Uri . IsWellFormedUriString ( contentOrFilePath , UriKind . RelativeOrAbsolute ) )
266
+ else if ( contentFormate == ContentFormate . AutoDetect )
260
267
{
261
- // The string looks like a URI, so try to parse it as a file URI
262
- var uri = new Uri ( contentOrFilePath ) ;
263
- if ( uri . IsFile )
268
+ if ( System . IO . Path . IsPathRooted ( contentOrFilePath ) )
264
269
{
265
- if ( System . IO . File . Exists ( uri . LocalPath ) )
270
+ // The string looks like a file path, so try to read the file
271
+ if ( System . IO . File . Exists ( contentOrFilePath ) )
266
272
{
267
- bytes = System . IO . File . ReadAllBytes ( uri . LocalPath ) ;
273
+ bytes = System . IO . File . ReadAllBytes ( contentOrFilePath ) ;
268
274
}
269
275
else
270
276
{
271
277
// The file does not exist, so treat the string as content
272
278
bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
273
279
}
274
280
}
281
+ else if ( Uri . IsWellFormedUriString ( contentOrFilePath , UriKind . RelativeOrAbsolute ) )
282
+ {
283
+ // The string looks like a URI, so try to parse it as a file URI
284
+ var uri = new Uri ( contentOrFilePath ) ;
285
+ if ( uri . IsFile )
286
+ {
287
+ if ( System . IO . File . Exists ( uri . LocalPath ) )
288
+ {
289
+ bytes = System . IO . File . ReadAllBytes ( uri . LocalPath ) ;
290
+ }
291
+ else
292
+ {
293
+ // The file does not exist, so treat the string as content
294
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
295
+ }
296
+ }
297
+ else
298
+ {
299
+ // The URI is not a file URI, so treat the string as content
300
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
301
+ }
302
+ }
275
303
else
276
304
{
277
- // The URI is not a file URI, so treat the string as content
305
+ // The string is not a file path or a URI, so treat it as content
278
306
bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
279
307
}
280
308
}
281
- else
282
- {
283
- // The string is not a file path or a URI, so treat it as content
284
- bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
285
- }
309
+
286
310
287
311
request . ContentType = LinqHelper . GetEnumMemberValue ( contentType ) ;
288
312
request . ContentLength = bytes . Length ;
0 commit comments